NB: Make sure you do a back up of your theme, files and database before attempting the tutorials
Intermediate
Last modified : Sep 11 2022
Estimated reading time : 0 minutes, 57 seconds - 60 words
Share the post "Display a Custom Post Type’s Categories"
Simply create a new Post Type and a taxonomy for your new Custom Post Type.
Once the taxonomy is set and your post type posts are published, here’s the query to use (in our example, we want the Region taxonomy):
This query can be used with the archive-region.php or taxonomy.php templates
Display a Custom Post Type's Categories
<?php $taxonomy = 'region'; // get the term IDs assigned to post. $post_terms = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) ); // separator between links $separator = ', '; if ( !empty( $post_terms ) && !is_wp_error( $post_terms ) ) { $term_ids = implode( ',' , $post_terms ); $terms = wp_list_categories( 'title_li' => '', 'style' => 'none', 'echo' => false, 'taxonomy' => $taxonomy, 'include' => $term_ids ); $terms = rtrim( trim( str_replace( '<br />', $separator, $terms ) ), $separator ); // display post categories echo 'Région : ' . $terms; } ?>