Pull related POD data into detail page

0

I have have a POD named countries and a POD named people. On the detail page of the country, I want to pull in people who are related to a country (bi-directional PICK). I am trying to use the country slug to find the people, but I can't get it working. No data is coming through.

Here is what I am using

My URL: http://cmfi.org/wherewework1/kenya

$location_slug  = pods_url_variable(1)
$missionary = new Pod('people', 'countrylocation.slug=$location_slug');

I know I have seen posts like this before. I have tried this also

$location_slug  = pods_url_variable(1);
$missionary = new Pod('people', '$location_slug');

Also tried this, but it pulls in all the people and not ones related to the country.

$country_slug  = pods_url_variable(last);
$missionary = new Pod('people', $country_slug);
$missionary->findRecords('t.name ASC' );

FYI, using 1.12.2

Can anyone point in the right direction?

Thanks! Shawn

asked Jan 6 at 8:40

senojeel

3

edited Jan 6 at 8:43

add comment
enter at least 15 characters

10 Answers

0

Sorry, on rereading your post, I interpreted it wrong. I also missed a real simple problem.

Use your original code, but change "$missionary" on line 3 to "$project".

answered Jan 16 at 3:39

chris.pilko

889

add comment
enter at least 15 characters
1

Try this:

$country_slug  = pods_url_variable(1);
$missionary = new Pod('people');
$missionary->findRecords('t.name ASC', -1, "countrylocation.slug = '$country_slug'");

answered Jan 6 at 10:52

chris.pilko

889

edited Jan 10 at 2:08

add comment
enter at least 15 characters
0

Thanks for the suggestion Chris,

When I use that, I get the following sql error:

SQL failed; SQL: SELECT SQL_CALC_FOUND_ROWS DISTINCT t.*, p.id AS pod\_id, p.created, p.modified FROM cmfi\_pod AS p INNER JOIN cmfi\_pod\_tbl\_people AS t ON t.id = p.tbl\_row\_id LEFT JOIN cmfi\_pod\_rel AS rel\_countrylocation ON rel\_countrylocation.field\_id = 6 AND rel\_countrylocation.pod\_id = p.id LEFT JOIN cmfi\_pod\_tbl\_countries AS countrylocation ON countrylocation.id = rel\_countrylocation.tbl\_row\_id WHERE p.datatype = 1 AND ( countrylocation.slug = kenya ) ORDER BY t.name ASC; Response: Unknown column 'kenya' in 'where clause'

answered Jan 7 at 7:12

senojeel

3

add comment
enter at least 15 characters
0

Sorry, the string in the WHERE statement needs to be quoted:

$missionary->findRecords('t.name ASC', -1, "countrylocation.slug = '$country_slug' ");

answered Jan 7 at 8:30

chris.pilko

889

add comment
enter at least 15 characters
0

Thanks Chris,

That worked great. I always get confused on what is quoted and not...

answered Jan 9 at 7:44

senojeel

3

add comment
enter at least 15 characters
0

Thanks Chris. That is what I needed.

I have another issue, if I need to start a new thread I will, but I think it is very similar to this. I keep on getting stuck on the secondary relationships.

On the people page we have been working on, at the bottom of that I have a listing of projects that they are related to. I cannot seem to find the right column to relate to. I have in my people POD a bi-direction PICK column called r_project and in my projects POD it is related to r_missionary. I am try to grab the slug of the missionary and relate to the projects pod that way. My code that doesn't work is below.

$missionary_slug = pods_url_variable(3);
$projects = new Pod('projects');
$missionary->findRecords('t.name ASC', -1, "r_missionary.slug = '$missionary_slug' ");     

With that code I will get unknown column "r_missionary.slug" .

If I try to use the dot traversal, r_project.r_missionary.slug, It seems to find that column, but no results show up and I do not get any errors.

Here is the page. http://cmfi.org/partner/discover-great-projects/missionary/jemoore

Thanks again for your help.

answered Jan 12 at 1:28

senojeel

3

add comment
enter at least 15 characters
0

we needed to list related items similar to what you want to do.

we used a helper we create a helper related_bodyparts_display

<?php
if (!empty($value) && is_array($value)) { 
  $output = array(); 
  foreach ($value as $v) { 
     $output[] = '<a href="' . $v['slug'] . '">' . $v['name'] .' </a>'; 
  } 
echo implode(', ', $output); 
}

then created a template called treatment1_related_bodyparts

<p>{@related_bodyparts, related_bodyparts_display}</p>

then in the pod page put this

<?php
echo $pods->showTemplate('treatment1_related_bodyparts');
?>

answered Jan 12 at 3:29

johnnyn

3

Thanks. The only difference is that I am using WP templates. I assume you are using POD Pages. I wonder if something like that would work for WP templates. – senojeel Jan 12 at 8:54
add comment
enter at least 15 characters
0

If you are grabbing this from your projects pod, you need to use the name of the pick column as it is defined in the projects pod. Try this:

$missionary->findRecords('t.name ASC', -1, "r_project.slug = '$missionary_slug' ");

answered Jan 12 at 4:28

chris.pilko

889

The problem with that is that r_project.slug will never equal $missionary_slug. Do I need to make the PICK columns different? Right now those to POD are joined by the project name. – senojeel Jan 12 at 8:57
The problem with that is that r_project.slug will never equal $missionary_slug. Do I need to make the PICK columns different? Right now those to POD are joined by the project name. Is that event possible? – senojeel Jan 12 at 8:59
add comment
enter at least 15 characters
0

The problem with that is that r_project.slug will never equal $missionary_slug. Do I need to make the PICK columns different? Right now those to POD are joined by the project name. Is that event possible?

answered Jan 14 at 7:50

senojeel

3

add comment
enter at least 15 characters
0

That was exactly right. Thanks so much for pointing that our Chris.

answered Jan 16 at 4:17

senojeel

3

add comment
enter at least 15 characters