Forum

Thread tagged as: Question, Blog

Filtering categories

In my blog there will be various categories to assign posts to. I have a handful of categories that I don't want to be included in a listing of categories output onto the blog page. I'm struggling to understand how to do this, or find the documentation that will explain specifically how to achieve it. What I have so far is this:

<?php 
     perch_categories(array(
     'set' => 'blog',
     'template' => 'blog_select_list.html'
   ));
?>

How, for example, will I stop a category called 'main-featured' from appearing?

Chris James

Chris James 0 points

  • 5 years ago

Haven't tested it, but I think you're looking for something like this:

<?php 
     perch_categories(array(
     'set' => 'blog',
     'template' => 'blog_select_list.html',
     'filter' => 'catSlug',
     'match' => 'neq',
     'value' => 'main-featured'
   ));
?>

and the docs you're looking for are here.

OK thanks Shane - that works perfectly. However - how can I exclude more than one category? I'm trying this but it doesn't work:

perch_categories(array(
    'set' => 'blog',
    'template' => 'blog_select_list.html',
   'filter' => 'catSlug',
   'match' => 'neq',
  'value' => array('main-featured', 'next-meeting')
));

Try:

<?php
    perch_categories(array(
      'set' => 'blog',
      'template' => 'blog_select_list.html',
      'filter'=>array(
      array(
          'filter'=>'catSlug',
          'match'=>'neq',
          'value'=>'main-featured'
      ),
      array(
        'filter'=>'catSlug',
        'match'=>'neq',
        'value'=>'next-meeting'
      ),
      ),
      'match'=>'or'
    ));
?>

That info is here

Thanks Shane for your help with this. However, that doesn't seem to work. It doesn't filter anything. Ive tried to understand the docs you linked to, but haven't made any progress! And they relate to 'perch_content_custom' - is this also applicable to 'perch_categories'?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, the filtering works the same.

I think you want this, however:

'match'=>'and'

perfect. Thank you both