这些args中的其他一切都很好。唯一不起作用的是排除uncategorized
类别我两个都试过了\'cat\' => \'-1\',
哪里1
是的IDuncategorized
我要排除的类别,以及tax_query
就像我下面讨论的部分一样:
array(
\'taxonomy\' => \'category\',
\'field\' => \'slug\',
\'terms\' => \'uncategorized\',
\'operator\' => \'NOT IN\',
),
以下是完整代码:
$tourDateArtists = get_terms(
array(
\'taxonomy\' => \'category\',
\'hide_empty\' => false,
)
);
$today = strtotime(\'today\');
foreach ( $tourDateArtists as $tourDateArtist ) {
$tourDateArtist_query = new WP_Query( array(
\'post_type\' => \'tour-date\',
// \'posts_per_page\' => -1,
\'meta_key\' => \'wpcf-tour-date\',
\'orderby\' => \'meta_value_num\',
\'order\' => \'ASC\',
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'category\',
\'field\' => \'slug\',
\'terms\' => array( $tourDateArtist->slug ),
\'operator\' => \'IN\',
),
array(
\'taxonomy\' => \'category\',
\'field\' => \'slug\',
\'terms\' => \'uncategorized\',
\'operator\' => \'NOT IN\',
),
),
\'meta_query\' => array(
array(
\'key\' => \'wpcf-tour-date\',
\'value\' => $today,
\'compare\' => \'>=\',
\'type\' => \'NUMERIC\',
),
),
));
if ( $tourDateArtist_query->have_posts() ) {
echo \'<div id="\' . $tourDateArtist->slug . \'" class="has-dates">\';
echo \'<h2><a href="/artists/\' . $tourDateArtist->slug . \'">\' . $tourDateArtist->name . \'</a></h2>\';
echo \'<ul class="\' . $tourDateArtist->slug . \'-tour-dates">\';
while ( $tourDateArtist_query->have_posts() ) {
$tourDateArtist_query->the_post();
echo \'<li class="tour-date-item">\';
echo \'<a href="\' . types_render_field( \'tour-date-link\' ) . \'">\';
echo \'<div class="tour-date-date">\' . types_render_field( \'tour-date\', array( \'format\' => \'F j, Y g:i a\') ) . \'</div>\';
echo \'<div class="tour-date-city-state">\' . types_render_field( \'city-state\' ) . \'</div>\';
echo \'<div class="tour-date-venue">\' . get_the_title() . \'</div>\';
echo \'</a>\';
echo \'</li>\';
}
echo \'</ul>\';
echo \'</div>\';
// echo (\'<a href="/tour-dates#\' . $parentSlug . \'" class="load-more-link">Show More Dates</a>\');
} else {
/* show \'no news\' message if no tour dates */
echo \'<div id="\' . $tourDateArtist->slug . \'" class="no-dates">\';
echo \'<h2>\' . $tourDateArtist->name . \'</h2>\';
echo \'<p>\' . $tourDateArtist->name . \' is not on tour.\' . \'</p>\';
echo \'</div>\';
}
$tourDateArtist_query = null;
wp_reset_postdata();
}
这是一个
foreach
但每次都应该测试一下
tax_query
正当知道为什么不排除我定义的类别吗:
uncategorized
?