Custom Taxonomy Not Registering?
-
Hello –
I am having an issue where the custom taxonomy I have created for my post type isn’t being recognized, they’re just showing as “uncategorized” even though they are set to “public” and showing that there are in fact registered in the CPT UI.
Is there a step I am missing possibly to get custom taxonomy to be recognized by WP? Also, this is on a Multisite install, which I believe is supported with the recent version of this plugin?
Thanks in advance.
-
Not quite following regarding the issue. You have a taxonomy, you’ve attached it to a post type, and it has a term of “uncategorized” ? Or that’s just how it’s showing in the post type posts list? Perhaps something on the frontend and display?
If you’re able to create terms for the taxonomy, and assign terms to the posts, then it’s getting recognized by WordPress as a whole. Display in various parts of the frontend likely need to have changes made to theme files to properly recognize the taxonomy. It sounds like the frontend may be looking for the out-of-box category taxonomy, not this new one.
Multisite shouldn’t be a contributing issue, as it would just save to that individual site’s options table, and be made available for it.
Hello –
Sorry for the confusion, see if I can clear this up a bit ??
For example, on the site I used VC’s Grid Builder to create something to grid out CPT’s on a page, and I had added the Post Categories item within the element. When I view the page with the post grid, I get this:
https://screencast.com/t/idFYh5u1Dy3
For testing sake, I had tried attaching WP Core Categories to the CPT and that worked fine and the category had showed where it says “uncategorized” in the screenshot.
For further testing just to rule out VC as the culprit, I installed another plugin that creates “Widgets” that allows for showing a number of custom post types in the footer (like Recent Posts), that too would only show the categories as “uncategorized” as well.
So I am not sure where to go from here and not sure if it is something I had missed in creating the the category taxonomy for my CPT.
Thanks for your time.
What’s the taxonomy slug you’re using for your version of categories? I’d contact Visual Composer support as well, to see what needs to be done, if anything to make their components recognize custom taxonomies. Both cases here sound like their code isn’t recognizing your items.
Here is the output from the Taxonomy category I created:
function cptui_register_my_taxes_video_category() { /** * Taxonomy: Video Categories. */ $labels = array( "name" => __( 'Video Categories', '' ), "singular_name" => __( 'Video Category', '' ), "menu_name" => __( 'Video Categories', '' ), "all_items" => __( 'All Video Categories', '' ), "edit_item" => __( 'Edit Video Category', '' ), "view_item" => __( 'View Video Category', '' ), "update_item" => __( 'Update Video Category', '' ), "add_new_item" => __( 'Add New Video Category', '' ), "new_item_name" => __( 'New Video Category', '' ), "parent_item" => __( 'Parent Video Category', '' ), "search_items" => __( 'Search Video Categories', '' ), "not_found" => __( 'No Video Categories Found', '' ), ); $args = array( "label" => __( 'Video Categories', '' ), "labels" => $labels, "public" => true, "hierarchical" => false, "label" => "Video Categories", "show_ui" => true, "show_in_menu" => true, "show_in_nav_menus" => true, "query_var" => true, "rewrite" => array( 'slug' => 'video-category', 'with_front' => true, ), "show_admin_column" => false, "show_in_rest" => false, "rest_base" => "", "show_in_quick_edit" => true, ); register_taxonomy( "video_category", array( "ultimate_video" ), $args ); } add_action( 'init', 'cptui_register_my_taxes_video_category' );
At this point, I’m convinced CPTUI is doing everything it should be doing here. The issues are the theme/VC components and what taxonomies it is set/knows to query for and display. Wish I could help more with that, but it’s kind of out of my hands.
@viablethought did you ever find a solution for this? Or are you still in limbo with it?
Hey Michael –
I have sort of a work around for what I was trying to do, but I know it isn’t the best solution and maybe you can help me correct this bit a code I am using to output taxonomy on a page using a shortcode:
function list_terms_custom_cat_taxonomy( $atts) { ob_start(); extract( shortcode_atts( array( 'custom_taxonomy' => 'video_categories', ), $atts ) ); global $post; $cattext .= get_the_term_list( $post->ID , $custom_taxonomy, '<strong>Category:</strong> ' , ', ' , ' ' ); $cattext .= ob_get_clean(); return $cattext; } add_shortcode( 'video_category_terms', 'list_terms_custom_cat_taxonomy' ); add_filter('widget_text', 'do_shortcode');
I have read that “extract” isn’t the best method for this but it has gotten me by thus far, but I searched tirelessly for another solution with no luck. Any suggestions or insight would be greatly appreciated!
Thanks
on the topic of extract(), all that does is turn array keys into their own variables.
For example, say you had the following array
$args = array( 'index1' => 'value1', 'index2' => 'value2', );
Running extract would provide you with the variables
$index1
that would have a stored value of'value1'
and$index2
with a value of'value2'
.If you were to store the return value of your
shortcode_atts()
call into a variable of$args
instead of passing it intoextract()
, then you’d need to change your code to simply pass in$args['custom_taxonomy']
into yourget_the_term_list()
call instead of$custom_taxonomy
. The array index/values weren’t extracted into their own variables.Regarding the topic of output buffering, I’d probably tweak the function to be closer to the following, including extract() removal.
function list_terms_custom_cat_taxonomy( $atts) { $atts = shortcode_atts( array( 'custom_taxonomy' => 'video_categories', ), $atts ); global $post; return get_the_term_list( $post->ID , $atts['custom_taxonomy'], '<strong>Category:</strong> ' , ', ' , ' ' ); } add_shortcode( 'video_category_terms', 'list_terms_custom_cat_taxonomy' ); add_filter('widget_text', 'do_shortcode');
If I’m not mistaken, there’s no need to be using both output buffering and variable concatenation. The variable concatenation would essentially be a version of output buffering, so you’re duplicating work. The post global may not be needed, as I think get_the_ID() would already be set up to grab the correct post ID, so that may be worth tinkering with.
Michael –
Thank you for taking the time to explain, I am still a bit of a n00b when it comes to WP programming, but your explanation here is on point! Your code snippet works flawlessly and I know have a better understanding of what it is doing.
Thank you so much for taking the time.
P.S. I still haven’t figured out why VC Grid Builder isn’t able to recognize my custom taxonomy, but using this has allowed for a pretty good work around ??
- The topic ‘Custom Taxonomy Not Registering?’ is closed to new replies.