Conditional queries WP_query based on term

Basically would like to show first posts with term = arts, if doesn’t exist then display posts with term = guides.

These are my two arguments, i’ve been trying to use has_term outside loop but not working.


if ( has_term( 'arts', 'postkicker' )){

    'post_type' => 'post',
    'taxonomy'  => 'postkicker',
    'term'      => 'arts',
    'orderby'   => 'date',
    'order'     => 'DESC'

} else {

    'post_type' => 'post',
    'taxonomy'  => 'postkicker',
    'term'      => 'guides',
    'orderby'    => 'date',
    'order'      => 'DESC'


$my_query = new WP_Query($args);

if ( $my_query->have_posts() ) :
    while ( $my_query->have_posts() ) : $my_query->the_post();
    the_title( sprintf( "<h1><a href='%s' rel='bookmark'>", esc_url( get_permalink() ) ), "</a></h1>" ); 


Any suggestions? Do I need to move my has_term within the loop?
Thanks in advance!

Read more here: Conditional queries WP_query based on term

Leave a Reply

Your email address will not be published. Required fields are marked *