0

I would like to display categories of a custom post type but not all of them. I'm using shortcode like this [categories exclude="56","59"] but it doesn't work. Can we exclude some categories in shortcode?

    function theme_shortcode_categories( $atts, $content = null) {
    extract( shortcode_atts( array(
        'categoriespostcount'   => 'on',
        'categorieshierarchy'   => 'on',
    ), $atts ) );

    $h = $categorieshierarchy == 'on'? "1" : "0";
    $c = $categoriespostcount == 'on'? "1" : "0";

    $cat_args = array('orderby' => 'name', 'post_type'   => 'theme_portfolio_image', 'taxonomy' => 'theme_portfolio_categories','show_count' => $c, 'operator' => 'NOT IN', 'hierarchical' => $h, 'echo' => 0);
    
    return wp_list_categories( $cat_args );
}

add_shortcode( 'categories', 'theme_shortcode_categories' );

1 Answer 1

0

Exclude needs to be in the $cat_args, and in the shortcode_atts. Like this: extract( shortcode_atts( array( 'exclude' => '', 'categoriespostcount' => 'on', 'categorieshierarchy' => 'on', ), $atts ) );

$cat_args = array(
    'exclude' => $exclude,
    'taxonomy' => 'theme_portfolio_categories',
    'show_count' => $c,
    'hierarchical' => $h,
    'echo' => 0
);
1

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.