Forum

Thread tagged as: Question, Problem, Blog

Perch Custom Filter by Slug

Hi All,

Just wondered if i could filter on the blog post category and match it to the current page slug?

i was trying this out, but no joy.

any help/advice be much appreciated.

<?php  
perch_blog_custom(array(
'template' => 'post_in_list--sidebar.html',
'filter' => 'category_names',
'match' => 'contains',
'value' => perch_get('s'),
'sort' => 'postDateTime',
'sort-order' => 'DESC',
'count' => 3
));
?>      
Steve Forbes

Steve Forbes 0 points

  • 7 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

Is the slug a category slug? I don't understand what the value of s is.

Hi Rachel,

The value of s is a slug generated from an id on a piece of content which is displayed using another template on the page, then i wish to display blog posts that have a blog category that match that slug. is this possible?

If i remove the filter code the latest posts are displayed and i can see the slugs on the url of the post title. I can also see the slugs i have added to the current page url.

my debug shows the below, i may be doing something completely the wrong way, so apologise in advance.

DIAGNOSTICS:
SELECT * FROM perch2_pages WHERE pagePath='/digital/web-design.php' LIMIT 1
SELECT * FROM perch2_pages WHERE pagePath='/digital/web-design.php' LIMIT 1
Using template: /templates/pages/attributes/seo.html
Using template: /templates/pages/attributes/body_attributes.html
SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='item' AND (regionPage='/digital/web-design.php' OR regionPage='*')
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='15' AND idx.itemRev='20')) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev
) as tbl GROUP BY itemID ORDER BY sortval ASC 
Using template: /templates/content/item--grid-lv3.html
SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
SELECT SQL_CALC_FOUND_ROWS DISTINCT p.* FROM perch2_blog_posts p WHERE postStatus='Published' AND postDateTime<='2014-09-05 10:06:00' AND category_names='web-design?s=digital' ORDER BY postDateTime DESC LIMIT 0, 3
Invalid query: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'category_names' in 'where clause'
SELECT FOUND_ROWS() AS `count` 
Using template: /templates/blog/post_in_list--sidebar.html

dan

Drew McLellan

Drew McLellan 2638 points
Perch Support

Should be possible.

'category' => perch_get('s')

Cheers Drew, whilst your in Brighton as well!!!

works perfect!!