0

I have to hide 3 categories from the list, at the moment to view the list I use this function

function genres() {
$args = array('hide_empty' => true, 'title_li'=> __( '' ), 'show_count'=> 0, 'echo' => 0 );             
$links = wp_list_categories($args);
$links = str_replace('</a> (', '</a>', $links);
$links = str_replace(')', '', $links);
echo $links; 
}



<?php genres(); ?>

i need to hide category id 1 and 2

1 Answer 1

1

You can use the exclude parameter:

'exclude'
(array|string) Array or comma/space-separated string of term IDs to exclude. If $hierarchical is true, descendants of $exclude terms will also be excluded; see $exclude_tree. See get_terms().

So with your $args:

$args = array(
    'hide_empty' => true,
    'title_li'   => '',
    'show_count' => 0,
    'echo'       => 0,
    // Excludes specific categories by ID.
    'exclude'    => array( 1, 2 ),
);
3
  • where i can paste this code inside my code? thank you in advance! Commented Jul 1, 2020 at 13:57
  • 1
    I solved it, thank you very much !! Commented Jul 1, 2020 at 14:00
  • Glad you figured it out, but just replace the whole $args = array( ... ); in your genres() function. Or you could just add , 'exclude' => array( 1, 2 ) to your existing $args/array.
    – Sally CJ
    Commented Jul 1, 2020 at 14:23

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.