I'm try to exclude a specific category from a list of categories that a custom post has (in this case 'Uncategorized' - ID: 1).

I've tried exclude:

  'include' => wp_list_pluck(get_the_category(), 'term_id'),
  'title_li' => '',
  'exclude' => 1

But it still appears. How can I make sure it never appears, even if a post is tagged 'Uncategorized'?

5 Answers 5


The wp_list_categories() function uses get_terms() behind the scenes, where the documentation for the exclude argument says:

If $include is non-empty, $exclude is ignored.

Instead you could try to exclude the term_id from the include values:

$include = wp_filter_object_list( 
    get_the_category(),   // Data
    [ 'term_id' => 1 ],   // Filter Data
    'NOT',                // Filter Option (exclude)
    'term_id'             // Pluck Data 

where we use wp_filter_object_list() to both filter and pluck. In general it could be better to check if the $include array is empty or not:

if( $include )
    // ... stuff above ...

    wp_list_categories( [
        'include'  => $includes,
        'title_li' => '',
    ] );

    // ... stuff below...
  • It seems to works for everything except when something is only tagged 'Uncategorized'... then it shows every category, including Uncategorized. Dang. Sep 23, 2016 at 11:54
  • 1
    yes, that's expected, hence my comment about checking if it's empty or not. It's the same with WP_Query, we have to check for empty arrays before assigning to the arguments. @DjangoReinhardt
    – birgire
    Sep 23, 2016 at 12:06
  • I updated the answer to make to more clear @DjangoReinhardt
    – birgire
    Sep 23, 2016 at 12:28

I build some tricky code to exclude category having ID 1. I'm trying to exclude category(ID:1) even remove from pluck also. Your code has include and exclude both parameter and this conflict the result.

//List the pluck...
$exclude_cat_id = 1;
$list_pluck = wp_list_pluck(get_the_category(), 'term_id');

//Get exlude pluck(ID:1) index...
$exclude_pluck = array_search($exclude_cat_id, $list_pluck);

//unset excluded pluck...

//Get all category except ID=1
$arrCat = wp_list_categories([
  'include' => $list_pluck,
  'title_li' => '',
  'exclude' => array($exclude_cat_id),
  'exclude_tree' => array($exclude_cat_id),

Hope this help you well!


If my case, the only time I didn't want the list of categories to appear was if a post was 'Uncategorized'. The simplest solution in the end was just to use in_category():

if (!in_category(1)) {
    // Display the categories this post belongs to, as links
            'include' => wp_list_pluck(get_the_category(), 'term_id'),
            'title_li' => ''
   $exclude = array();
   foreach (get_categories() as $category) 
   {$exclude[] = 1;}
   if (! empty($exclude)) 
   { $args .= ('' === $args) ? '' : '&';$args .= exclude='.implode(',', $exclude);}
  • 1
    Explanation for the code would be great!
    – bravokeyl
    Sep 23, 2016 at 13:38
  • just put in your functions.php file.. Sep 23, 2016 at 13:42

How can I display only the specific category when accessing the posts related to that category? For example, I want to show only CSR Events under Categories When accessing posts related to CSR events. Here's the link to CSR post https://www.mi-eq.com/blood-donation-compaign/

Screenshot: https://i.stack.imgur.com/YoTfk.jpg

Similarly, when visiting posts related to other categories, only the specific category will be shown. Is there any simplest to achieve that?

  • Hey David, you've posted your question as an answer. Create a new question instead. Jul 2, 2020 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.