Timber: Exclude category method

738 Views Asked by At

I wish to exclude some categories from my output using the statement below but only the first argument '1' is honoured.

Can anyone determine why the following arguments are not also excluded (the id's are correct, if i change the order the first id is always excluded):

$context['categories'] = Timber::get_terms('category', array( 'exclude' =>  14, 13, 1));

These didn't work either

$context['categories'] = Timber::get_terms('category=-1,-13,-14');

$context['categories'] = Timber::get_terms('cat=-1,-13,-14');
1

There are 1 best solutions below

3
On BEST ANSWER

Second two lines of code will never work according to my knowledge because wordpress do not accepting the negative value in exclude parameter. Negative value is taken in only post_per_page only.

Try below code if you are not using custom taxonomy :

$context['categories'] = Timber::get_terms('cat', array( 'hide_empty' => 1,'exclude' =>  1));

If you are using the custom taxonomy than it will be something like below you need to change the slug only

$context['categories'] = Timber::get_terms('product_cat', array('hide_empty' => 0, 'parent' =>0));