Custom Taxonomy not recognized
-
When I use CPT to create custom taxonomies for my custom post types, they are not being recognized by WP. So I can’t use them in ‘tax_query’
my query works fine when using the core WP categories.
Any thought?
-
The other thing is that they don’t show up under quick-edit, which would also be very helpful.
Aren’t being recognized in what way? Are they showing up when working with posts in the admin side of things? For example you’re able to create terms and also assign them to posts?
Did you make sure to set “Show in quick/bulk edit panel.” to true for the second part? It’s towards the bottom of the list for the taxonomy settings.
They don’t seem to be recognized by tax_query. Do I need to edit the query_var_slug?
The name is class_type, so I’m using ‘taxonomy’ => ‘class_type’,
I got them to show up in the quick edit, but they appear like tags vs. categories. Any way to get them to show up as check boxes?
Would access to the site help?
They show up in Advanced Custom Fields, but on the actual post, it looks like a tag vs. a category.
Is there a way to hide these on the edit post page? I’m using them as a field in ACF and don’t want both showing up.
Thanks.
The way you’re specifying the taxonomy looks right, and I don’t seen “class_type” being listed as a reserved name.
What’s your WP_Query args looking like for your attempts with the custom taxonomy?
Set your taxonomy to be hierarchical if you want them to behave like categories instead of tags.
Regarding metaboxes in the post editor, the easiest way would be to click “Screen Options” at the top and toggle off the appropriate metaboxes. This method is a per-user detail.
We don’t have a UI field for “meta_box_cb” in the current release. It’s slated for 1.6.0, but we’re not there yet. Once that is available though, passing “false” to “meta_box_cb” will hide it for everyone and not make it available to be shown.
Here’s what I’m testing with:
<?php
$args = array(
‘post_type’ => ‘classes_camps’,
‘tax_query’ => array(
array(
‘taxonomy’ => ‘class_type’,
‘field’ => ‘slug’,
‘terms’ => array(‘first-stage’),
‘operator’ => ‘IN’
)
),
‘posts_per_page’ => -1
);$query = new WP_Query($args);
while($query -> have_posts() ) : $query -> the_post();
?><h1><?php the_title(); ?></h1>
<?php endwhile; wp_reset_query(); ?>
What I ultimately need to do:
<?php
$args = array(
‘post_type’ => ‘classes_camps’,
‘tax_query’ => array(
‘relation’ => ‘AND’,
array(
‘taxonomy’ => ‘class_term’,
‘field’ => ‘slug’,
‘terms’ => array(‘2018-summer’),
‘operator’ => ‘IN’
),
array(
‘taxonomy’ => ‘class_type’,
‘field’ => ‘slug’,
‘terms’ => array(‘skills’),
‘operator’ => ‘IN’
),
array(
‘taxonomy’ => ‘session’,
‘field’ => ‘slug’,
‘terms’ => array(‘afternoon’),
‘operator’ => ‘IN’
)
),
‘posts_per_page’ => -1
);$query = new WP_Query($args);
while($query -> have_posts() ) : $query -> the_post();
?><h1><?php the_title(); ?></h1>
<?php endwhile; wp_reset_query(); ?>
and this is working, but it’s not the ideal solution. I’d prefer the taxonomies attached to the post type:
<?php
$args = array(
‘post_type’ => ‘classes_camps’,
‘tax_query’ => array(
‘relation’ => ‘AND’,
array(
‘taxonomy’ => ‘category’,
‘field’ => ‘slug’,
‘terms’ => array(‘2018-summer’),
‘operator’ => ‘IN’
),
array(
‘taxonomy’ => ‘post_tag’,
‘field’ => ‘slug’,
‘terms’ => array(‘first-class’),
‘operator’ => ‘IN’
),
array(
‘taxonomy’ => ‘post_tag’,
‘field’ => ‘slug’,
‘terms’ => array(‘afternoon’),
‘operator’ => ‘IN’
)
),
‘posts_per_page’ => -1
);$query = new WP_Query($args);
while($query -> have_posts() ) : $query -> the_post();
?><h1><?php the_title(); ?></h1>
<?php endwhile; wp_reset_query(); ?>
Thanks.
I think I figured something out.
So, I got the custom taxonomies showing up correctly, but I realize that when I assign them using the ACF interface, it doesn’t actually assign them to the post. I may have to use the other interface to get it to work.
I’ll check with ACF as well.
Unable to confirm myself, but it almost sounds like ACF is using the taxonomy terms to create a list of items, and is instead saving to their own settings instead of WordPress core taxonomy tables.
As a test, perhaps save and use the default metaboxes to assign some terms and then re-try with your desired WP_Query args and see if you get expected results.
Yep, it’s ACF. Works like a charm using the default metaboxes.
Thanks.
Silly ACF
The topic ‘Custom Taxonomy not recognized’ is closed to new replies.