I’m really stumped as to why the following would not work:
– custom post type “concert”
– has custom taxonomy “concert_year” attached in ACF
In my loop, I’m getting all published “concert” posts displayed:
$args = array( 'numberposts' => -1, 'post_type' => 'concert', 'post_status' => 'publish', ); $the_query = new WP_Query( $args );
I can output the taxonomy term_id by having
the_field('concert_year'); in the loop (it’s set to return the ID in ACF).
This only works as long as I don’t add a taxonomy query in the args, however.
$args = array( 'numberposts' => -1, 'post_type' => 'concert', 'post_status' => 'publish', 'tax_query' => array( array( 'taxonomy' => 'concert_year', 'field' => 'term_id', 'terms' => array( 26 ), ), ), ); $the_query = new WP_Query( $args );
always has zero results, no matter if I use term_id or the slug.
I’m sure there’s a ridiculously obvious error here, but frustratingly I can’t spot it.
Have you set the taxonomy field to map to the post? check the create terms, save terms and load terms settings in the field settings.
Otherwise the taxonomies you select there will just be a meta value on the post. you could still query on it but it would be a meta_query.
the taxonomy field is indeed set to map to the post (if I understand it correctly): Create, Save and Load Terms are all set to Yes.
The taxonomy is shared between this post type, three more custom pst types, and an options page, if that makes any difference.
Thanks for any+all hints!
Okay.. when you say it’s shared.. do you mean that you’ve registered the taxonomy for the post type?
Because I believe you have to register the taxonomy for the post type as well (it would make the native meta box appear). Otherwise ACF can’t mapp the terms selected.
Yes, the taxonomy is registered for all post types that use it:
register_taxonomy( "year", array( "attachment", "concert", "interpret", "composer", "longread" ), $args );
Could the error be in how the taxonomy is registered and what ACF uses as taxonomy name (“year” vs “concert_year”)?
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!