how I can get the categories from the same global search
You can add a taxonomy
attribute to your shortcode and then pass the value to get_query_terms_list()
, like so:
add_shortcode( 'bd_terms_list', 'bd_terms_list_custom_callback');
function bd_terms_list_custom_callback( $args ){
$atts = shortcode_atts( array( // list of default attributes
'taxonomy' => 'gd_place_tags',
'sep' => '', // optional, but you might use it someday? :)
), $args );
return get_query_terms_list( $atts['taxonomy'], $atts['sep'] );
}
See the Shortcodes API on Codex for more details about handling shortcode attributes.
And for example with the default post_tag
and category
taxonomies included in WordPress core, you can display the tags and categories in separate list like so:
Tags: [bd_terms_list taxonomy="post_tag"]
Categories: [bd_terms_list taxonomy="category"]
So you really just need to use the correct taxonomy slug, just like you could see above.
In response to your comment:
the slug for category is ‘gd_postcategory’ without the underscore for
some reason. I’m not sure how to fix the underscore, so I added 2 x
shortcodes now instead of using the more elegant taxonomy=”category”.
It works 🙂
Why would you need to “fix the underscore”?
And you do know the differences between taxonomies and terms, don’t you? (see https://developer.wordpress.org/themes/basics/categories-tags-custom-taxonomies/)
So for example, if I registered custom “tag” and “category” taxonomies named gd_place_tags
and gd_postcategory
respectively, then I would display the tag/category list like so:
Tags: [bd_terms_list taxonomy="gd_place_tags"]
Categories: [bd_terms_list taxonomy="gd_postcategory"]
But if you’re absolutely certain the above just doesn’t work for you, then yes of course, you could just create another shortcode which calls the get_query_terms_list()
function. 🙂
However, if I were you, I would try again with the modified bd_terms_list_custom_callback()
function as well as the HTML code above, but I would double-check that I’m using the correct taxonomy slugs (and not the label like “My Taxonomy” or even the slug of a term in the taxonomy like my-category-in-my-taxonomy
).