I would like to group posts of a custom post type based on tags, but the default functionality does not do for the project I am working on.
I want the user to be able to select only one tag, not multiple tags, from a list of all the tags entered for that custom post type (drop down or radio buttons).
The user can create as many tags as he wants from the page for adding a custom taxonomy, and all these tags will be listed in the meta box on the single custom post page.
Any suggestion?
In my last project i had the same issue and i just used this:
first get the list of tags to a var using the get_categories function by passing the right taxonomy like this:
then create the arguments for the meta box
then add the meta box
then all you have to do is create a function to show the meta box
and save it on post save
hope this helps
I tried to show the list and it does work if you use
post_tag
orcategory
, but it gives me the list of the default post type tags or categories.I want to have the list of the custom taxonomies for my custom posts.
My custom post type is “au-gallery” and my custom taxonomy is “gallery” therefore I tried
$args = array(
'type' => 'au-gallery',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 0,
'taxonomy' => 'gallery'
);
but I got only an empty list.
I had a look at
get_the_term_list
andget_the_terms
but those functions requires the post ID so…do I need to run a loop for al my custom posts to get this list or is there a better way??For custom taxonomies, I found a solution without writing a
save_post
hook.When register a taxonomy, need to specify
'meta_box_cb' => 'single_taxonomy_select_meta_box'
For more details, please download this gist
If you want to show all the tags in the select box dropdown and also want to select the current tag should be on top in the select box
And also you will move to the tag page while selecting the tag from the select box