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.

<?php

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

$args=array(
    'post_type' => 'post',
    'taxonomy'  => 'postkicker',
    'term'      => 'arts',
    'orderby'   => 'date',
    'order'     => 'DESC'
);

} else {

$args=array(
    '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>" ); 

    endwhile;wp_reset_postdata();endif; 
?>

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


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: