wp get taxonomy terms code example
Example 1: wordpress get taxonomy of a post
<?php $term_obj_list = get_the_terms( $post->ID, 'taxonomy_name' ); ?>
Example 2: get taxonomy name in singhle post
$terms = get_the_terms( $post->ID, 'your-taxonomy' );
if ( !empty( $terms ) ){
$term = array_shift( $terms );
echo $term->slug;
}
Example 3: wp_query get by taxonomy
$the_query = new WP_Query( array(
'post_type' => 'Adverts',
'tax_query' => array(
array (
'taxonomy' => 'advert_tag',
'field' => 'slug',
'terms' => 'politics',
)
),
) );
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
the_title();
}
}