Forum
Getting Blog Posts from Multiple Categories
Hi,
I'm trying to get a list of blog posts from a list of multiple categories.
My template for returning a list of categories for the current post looks like this:
"gallery/<perch:category id="catSlug" />",
This returns a string like this:
"gallery/forms","gallery/boots",
I then pass this into a perch_blog_custom function to return other results categorised in the same way, but not matchin the current post's slug:
<?php
$cat = perch_blog_post_categories(perch_get('s'), array(
'template' => 'cat-name.html',
), true);
if($cat<>''){
echo "<h2>Related Work</h2>";
$cat = substr($cat, 0, -1); //remove trailing comma
perch_blog_custom(array(
'template' => 'post_in_list-related.html',
'category' => array($cat),
'category-match' => 'any',
'filter' => 'postSlug',
'match' => 'neq',
'value' => perch_get('s'),
'sort-order' => 'DESC'
));
}
?>
This returns no results (should return 2).
If I copy the returned string ("gallery/forms","gallery/boots") directly into the category array in perch_blog_custom the function works.
Is there any reason why entering a list of categories into the array in this way (as a variable) shouldn't work?
Thanks!
Just to cover all bases - have you tried with debug on, to see what query is being passed when it's not working?
A string's no good - you need to pass an array of categories. To get that, use
skip-template
.Great! Thanks Drew - I knew it was something along those lines, but couldn't quite imagine what the solution would be.