0
{exp:channel:entries channel="courses" dynamic="no" orderby="title" sort="asc" search:course_category="{embed:entry_id}" search:sub_cat="{embed:subentry_id}"}
Test {course_category}{entry_id}{/course_category} vs {embed:entry_id} - {sub_cat} {entry_id}{/sub_cat} vs {embed:subentry_id}
{embed="includes/.testcourse" compare="{course_category}{url_title}{/course_category}" page="{embed:page}" subcat="{embed:subcat}" subcatc="{sub_cat}{url_title}{/sub_cat}" title="{name_for_menu}" url="{url_title}" brand="{embed:brand}" {if url_title == "{embed:url_title}"}class="active"{/if}}

{/exp:channel:entries}

Ok, this code basically checks the category and the sub-category of the course are correct before adding them to the page.

Heres the bad part:

Test 15 vs 5 - 29 vs 9 Makaton Signing for Babies

Test 15 vs 5 - 29 vs 9 Parent and Carer

DOH! Clearly they don't match, its just found them because it contains them

Now, I figured this was just because I hadn't used exact match searching, so i changed the code to:

{exp:channel:entries channel="courses" dynamic="no" orderby="title" sort="asc" search:course_category="={embed:entry_id}" search:sub_cat="={embed:subentry_id}"}
Test {course_category}{entry_id}{/course_category} vs {embed:entry_id} - {sub_cat}{entry_id}{/sub_cat} vs {embed:subentry_id}
{embed="includes/.testcourse" compare="{course_category}{url_title}{/course_category}" page="{embed:page}" subcat="{embed:subcat}" subcatc="{sub_cat}{url_title}{/sub_cat}" title="{name_for_menu}" url="{url_title}" brand="{embed:brand}" {if url_title == "{embed:url_title}"}class="active"{/if}}
{/exp:channel:entries}

And now no entry shows despite (more code from the previous debug): Test 5 vs 5 - 10 vs 10 Business Administration Test 5 vs 5 - 10 vs 10 ChildCare Test 5 vs 5 - 10 vs 10 Customer Service Test 5 vs 5 - 10 vs 10 Hospitality and Catering Test 5 vs 5 - 10 vs 10 Hospitality Supervision

Now I can't see why they wouldn't match the correct ones on an exact match search (I've tried it with quotes around to check for nbsp or similar)

As you may have guessed {course_category} and {sub_cat} are playa fields. So how do I do an exact match search vs a playa element?

Thanks!!

1 Answer 1

1

This is no the way to go about filtering on a Playa field. The reason it's not working is because Playa does not store what you might expect in the custom field. A typical entry looks like this:

[9] [makaton-signing-for-babies] Makaton Signing for Babies

What you want to do is use the Playa Parents and Playa Children tags, which can be filtered using all standard Channel Entries parameters.

7
  • Ok, so if that is the case, why when I output the exact same tag, does it not display that? Makes it very difficult to debug your code! Also why on earth would anyone store data like that??? Its got to be in an array or at least csv format or some other accessible format or it makes no sense at all. Oh and I need to check if it has TWO parents, If I do a exp:playa:parents inside a exp:playa:parents then its horribly slow and uses too many resources per page load for this to be practical.
    – Drenzul
    Commented Feb 13, 2013 at 9:45
  • Also since the sub-category can be in many main categories, parent of a parent wouldn't work as the sub-category needs to be in several of the main parent classes, but the course is only pulled in when it is in the correct category and sub-category so the code needs to check both which if you can't search a playa field directly, it can't do.... at least not without just pulling in every field and checking the url. I find it very hard to believe there isn't another way to do this so we are only searching the URL part of the playa field.
    – Drenzul
    Commented Feb 13, 2013 at 12:35
  • Playa uses the data it stores in its own relationships table (exp_playa_relationships) to display each related entry's data on the front-end. The data stored inside the custom field table cell is there primarily for exposing the data via search. Commented Feb 13, 2013 at 13:02
  • Still would be nice to be able to access it in a useful way..., if it wasn't in a parameter I could access it vis {field}{entry_id}{/field} so why there isn't a way to do this via the search channel parameter I'm not sure. I've tried accessing the data as an array and that didn't work either, I may try to see if matching vs "[{entry_id}] [{url_title}] {title}" works later but for now I'm just lettering it use the 'contains' match then I've put in an extra layer to check there aren't any extra ones been pulled in.
    – Drenzul
    Commented Feb 13, 2013 at 15:16
  • I've clarified your question title - perhaps the Pixel & Tonic folks will come by and help. Commented Feb 13, 2013 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.