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;
});
My taxonomy is called
recipe-categories
insidewp_term_taxonomy
and I want to be able to pull in all the categories inside the Categories Widget.recipe
is my custom post type.Url string is
taxonomy=recipe-categories&post_type=recipe
Here are all the categories that I have:
All that I'm getting back is the post
categories and not my recipe
categories as shown below:
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;
});
My taxonomy is called
recipe-categories
insidewp_term_taxonomy
and I want to be able to pull in all the categories inside the Categories Widget.recipe
is my custom post type.Url string is
taxonomy=recipe-categories&post_type=recipe
Here are all the categories that I have:
All that I'm getting back is the post
categories and not my recipe
categories as shown below:
1 Answer
Reset to default 1The 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.