Exclude category from list - Wordpress
12,399
You can exclude id in array.You can pass multiple ids in exclude parameter like
$args = array(
'hide_empty' => 1,
'exclude' =>array(1,2,3) // desire id
);
$categories = get_categories($args );
Author by
kesernio
I design interfaces, shape brands, and craft interactive experiences.
Updated on June 04, 2022Comments
-
kesernio almost 2 years
I'm trying to exclude a category from displaying in the following list:
<?php $categories = get_categories( 'orderby=id&exclude=1,'. getOption('promo-categorie', false) ); foreach( $categories as $category ) : $active = ( !is_home() && get_query_var( 'cat' ) == $category->term_id )? ' style="color: ' . getOption($category->category_nicename . '-color', false) . '"' : ''; $catLink = ( get_query_var( 'cat' ) == $category->term_id ) ? get_bloginfo( 'wpurl' ) : get_category_link( $category->term_id ); ?> <a class="nav-links" href="<?php echo ( get_query_var( 'sort' ) == 'list' )? add_query_arg( array( 'sort' => 'list' ), $catLink ) : $catLink ?>" <?php echo $active; ?>><?php echo $category->name; ?></a> <?php endforeach; ?>
I'm a total newb with PHP, but from what I can tell "promo-categorie" is being excluded. In addition, I would like to exclude another category.
Any help would be appreciated.
-
kesernio over 9 yearsThat did it. Thanks for your assistance!