我希望有人可以帮助发现问题所在。我有一个名为“events_cat”的自定义分类法我试图获取分类词11中显示的所有帖子类型“事件”,但是下面的代码正在引入不在该分类术语中的事件我可以'看到错误。可能导致问题的任何想法?:
<?php
$args = array(
'post_type' => 'event',
'posts_per_page' => -1,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'events_cat',
'field' => 'term_id',
'terms' => array(11),
),
));
$upcomingEvents = new WP_Query($args); ?>
答案 0 :(得分:1)
$custom_args=array(
'post_type' => "event",
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> -1,
'hierarchical' => 1,
'exclude' => '',
'include' => '',
'number' => '',
'tax_query' => array(
array(
'taxonomy' => 'events_cat',
'field' => 'id',
'terms' =>"11"
)
),
'orderby' => 'id',
'order' => 'ASC'
);
$custom_my_query = null;
$custom_my_query = new WP_Query($custom_args);
$custom_my_total_count = count($custom_my_query);
if( $custom_my_query->have_posts() )
{
while ($custom_my_query->have_posts()) : $custom_my_query->the_post();
?>
<a href="<?php echo get_permalink();?>"><?php echo get_the_title($post->ID);?></a>
<?php
endwhile;
}
wp_reset_query($custom_my_query); // Restore global post data stomped by the_post().
}