How to filter content based on ID with match and value?

  • I'm trying to filter some basic content. It's not working. Here's what I have - a template with one region as:

    Code
    1. <perch:content id="filter-tags" type="select" label="Category" options="available,1bed,1bed,2bed,3bed,4bed" allowempty="true" required="false" />


    And the page has this as the content_custom code:


    With that, nothing is filtering, it's just showing all the content.


    For context - these are cards with tags the content editor has chosen. I'm looking to show only the cards with the 'available' selection.

  • You’ll get two sets of results. One filtered and the other unfiltered. If the filtering isn’t set up right then you won’t get any results and will just see the second set of results. Comment out the second function call and turn on debug on the page to see the database results.

  • Ah. Sorry about that. Yes, so the results are returning nothing. With debug on, here is the message:

    Code
    1. Debug Message
    2. [1] SELECT * FROM perch2_pages WHERE pagePath='/noho/index.php' LIMIT 1
    3. [14] SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/noho/index.php' OR regionPage='*' ORDER BY regionPage DESC
    4. [1] SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='Listing Cards' AND (regionPage='/noho/index.php' OR regionPage='*')
    5. [55] SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID=2020 AND idx.itemRev=688)) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID, pageID, itemJSON, sortval ORDER BY sortval ASC
    6. [2] Using template: /templates/content/listing-card.html
  • Ah, I had the filter off when I grabbed that. Whoops. Here is the debug message:

    Code
    1. Debug Message
    2. [1] SELECT * FROM perch2_pages WHERE pagePath='/noho/index.php' LIMIT 1
    3. [14] SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/noho/index.php' OR regionPage='*' ORDER BY regionPage DESC
    4. [1] SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='Listing Cards' AND (regionPage='/noho/index.php' OR regionPage='*')
    5. [nil] SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID=2020 AND idx.itemRev=688)) AND ((idx.indexKey='filter-tags' AND idx.indexValue='available')) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID, pageID, itemJSON, sortval ORDER BY sortval ASC
    6. Using template: /templates/content/listing-card.html

    And this is using this the call:


    PHP
    1. <?php
    2. perch_content_custom('Listing Cards', [
    3. 'filter'=>'filter-tags',
    4. 'match'=>'eq',
    5. 'value' => 'available',
    6. ]);
    7. PerchUtil::output_debug();
    8. ?>
  • It looks like nothing is matching that value in your filter. I would suggest that your select option isn't setting the right value. Have you saved the content since changing the template? Putting <perch:showall> in your template will show you the values set for the content.

  • Thanks for the notes. Everything is saved, so that's not it. But I added the showall tag and it indeed shows the ID's I'm looking for.



    So why isn't it filtering the "available" array for the "filter-tags" ID with this call:


    PHP
    1. <?php
    2. perch_content_custom('Listing Cards', [
    3. 'filter'=>'filter-tags',
    4. 'match'=>'eq',
    5. 'value' => 'available',
    6. ]);
    7. ?>
  • If you've got multiple select tags, as Mark astutely suggests you might, then those IDs need to be different. Also try not to use the hyphen in the ID. It's not supported:


    Quote

    A unique identifier for the item within that template. This should be lowercase letters, numbers and underscores only.

  • Oh, so filtering doesn't work with 'select' dropdown options? Oye.


    Well, I went ahead then and made an additional checkbox for the CMS users, so the checkbox has an ID and that worked. Filtered. Never knew that was limited to certain region types.


    Thanks for pointing that out!

  • It should work fine as far as I am aware. Does your template have multiple select entries in it? Do they have the same ID name? If they do then that's where things are going wrong. Perhaps share the whole template so we can see what's going on.