Home › Forums › Front-end Issues › Taxonomy tags not found in front-end
Hi,
I’ve got a problem which is probably easy to solve, but I can’t get it done… 🙁
I’m using custom post types with tags. When I add a tag in the back-end, let’s say “marketing”, I can see it on the front-end when I look at all the available tags. But not on a single (custom) post (type), then they are not visable. And if I click on a term and go to the page with all the posts containing that term (domain.com/tag/marketing) it says: Nothing found.
To be clear: if I add a term to a “normal” post (not a custom post type), it works as it should: tag term is visable on single post and when I click on the term I see an overview with posts with that tag term.
At first I created the CPT with the following code:
//Custom post type cases
add_action('init', 'cases_register');
function cases_register() {
$args = array(
'labels' => array(
'name' => __('Cases'),
'singular_name' => __('Case'),
'add_new' => __('Add case'),
'add_new_item' => __('Add case'),
'edit_item' => __('Edit case'),
'new_item' => __('New case'),
'all_items' => __('All cases'),
'view_item' => __('View case'),
'search_items' => __('Search case'),
'not_found' => __('No case found'),
'not_found_in_trash' => __('Nothing found in trash'),
'menu_name' => 'Cases'
),
'public' => true,
'show_ui' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'query_var' => true,
'show_in_nav_menus' => true,
'capability_type' => 'post',
'hierarchical' => true,
'rewrite' => true,
'supports' => array('title', 'thumbnail', 'comments'),
'taxonomies' => array('cases', 'post_tag')
);
register_post_type( 'cases' , $args );
}
When this did not work I tried using the tags field in ACF. But the result is the same. It looks as if the tags are not “tied” to the custom posts.
Anybody any ideas?
Thanks!
I seem to have solved this in the end. I added this code to my plugin:
function wpa_cpt_tags( $query ) {
if ( $query->is_tag() && $query->is_main_query() ) {
$query->set( 'post_type', array( 'post', 'case' ) );
}
}
add_action( 'pre_get_posts', 'wpa_cpt_tags' );
This can also be added to functions.php.
The topic ‘Taxonomy tags not found in front-end’ is closed to new replies.
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.