我已经阅读了其他空数组文章,无法找到解决方案。我有这个数组(下面)。
<?php
$args=array(
'post_type' => 'vehicle-brochure',
'post_status' => 'publish',
'order'=>'ASC',
'tax_query' => array(
array(
'taxonomy' => 'brochure-bucket',
'field' => 'id',
'terms' => 655,
),
array(
'taxonomy' => 'brochure-bucket',
'field' => 'id',
'terms' => 605,
'operator' => 'NOT IN'
)
),
);
?>
我现在正在尝试的事情。
<?php if(!empty($args)):
echo "x";
else:
echo "y";
endif; ?>
答案 0 :(得分:0)
猜猜我只需要离开它 - 简单的解决方案。
<?php $args = array(); ?>
<?php $the_query = new WP_Query( $args ); ?> // WHAT I WAS MISSING
<?php if ( $the_query->have_posts() ) : ?> // WHAT I WAS MISSING
// WHAT TO SHOW IF THERE'S ANY POSTS //
<?php endif; ?> //Fail, like I want if nothing is found.