0

I wanted to see if this was possible, but I want to include the custom post type custom taxonomy categories inside the WordPress Categories widget.

I know that there is a filter as shown below:

add_filter('widget_categories_args', function() {
    $params['post_type'] = array('post', 'recipe');
    return $params;
});
  1. My taxonomy is called recipe-categories inside wp_term_taxonomy and I want to be able to pull in all the categories inside the Categories Widget.

  2. recipe is my custom post type.

  3. Url string is taxonomy=recipe-categories&post_type=recipe

Here are all the categories that I have:

enter image description here

All that I'm getting back is the post categories and not my recipe categories as shown below:

enter image description here

1 Answer 1

1

The widget class uses wp_list_categories() which supports all the parameters for get_terms() like taxonomy which you can use to make the widget lists categories in a taxonomy other than category.

So your code would be:

add_filter('widget_categories_args', function( $params ) {
//  $params['post_type'] = array('post', 'recipe'); // post_type is not a standard parameter for get_terms()
    $params['taxonomy'] = 'recipe-categories';
    return $params;
});

However, the widget only supports a single taxonomy because wp_list_categories() uses taxonomy_exists() which doesn't support multiple taxonomies. Here's the relevant code in wp_list_categories() which causes the limitation:

if ( ! taxonomy_exists( $parsed_args['taxonomy'] ) ) {
    return false;
}

So if you want to use multiple taxonomies, then you'd need a plugin for that (i.e. one that provides a similar widget) or you can code your own widget class.

Your Answer

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

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