Pull related POD data into detail page
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
edited Jan 6 at 8:43
10 Answers
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".
Try this:
$country_slug = pods_url_variable(1);
$missionary = new Pod('people');
$missionary->findRecords('t.name ASC', -1, "countrylocation.slug = '$country_slug'");
edited Jan 10 at 2:08
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'
Sorry, the string in the WHERE statement needs to be quoted:
$missionary->findRecords('t.name ASC', -1, "countrylocation.slug = '$country_slug' ");
Thanks Chris,
That worked great. I always get confused on what is quoted and not...
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.
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');
?>
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' ");
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?
That was exactly right. Thanks so much for pointing that our Chris.


