好了,我差不多完成了90%,唯一一个不断被打破的部分是当我试图排除一个特定的分类术语时。
细分:
排序:(\'v\\u sort\'=>\'views\')这是通过流行的WP Postviews插件完成的。
帖子类型:帖子、视频、音乐、相册。
日期:最近30天。
Excluded Taxonomy Term: 分类法=内容,术语=indy。
迄今为止有效的代码。
<?php
// Create a new filtering function that will add our where clause to the query
function filter_where( $where = \'\' ) {
// posts in the last 30 days
$where .= " AND post_date > \'" . date(\'Y-m-d\', strtotime(\'-30 days\')) . "\'";
return $where;
}
add_filter( \'posts_where\', \'filter_where\' );
// The Query
$the_query = new WP_Query( array(
\'posts_per_page\' => \'5\',
\'v_sortby\' => \'views\',
\'post_type\' => array( \'post\', \'music\', \'videos\', \'albums\' ) )
);
remove_filter( \'posts_where\', \'filter_where\' );
// The Loop
while ( $the_query->have_posts() ) :
$the_query->the_post(); ?>
I\'m doing stuff here...
<?php endwhile;
/* Restore original Post Data
* NB: Because we are using new WP_Query we aren\'t stomping on the
* original $wp_query and it does not need to be reset.
*/
wp_reset_postdata(); ?>
如何排除内容分类术语indy?顺便说一句,我是个初学者。
SO网友:birgire
您可以尝试:
$the_query = new WP_Query( array(
\'posts_per_page\' => \'5\',
\'v_sortby\' => \'views\',
\'post_type\' => array( \'post\', \'music\', \'videos\', \'albums\' ),
\'tax_query\' => array(
array(
\'taxonomy\' => \'content\',
\'field\' => \'slug\',
\'terms\' => array( \'indy\' ),
\'operator\' => \'NOT IN\'
)
)
));
要排除
indy
中的术语
content
分类学
SO网友:Chozen
Solved.
<?php
// Create a new filtering function that will add our where clause to the query
function filter_where( $where = \'\' ) {
// posts in the last 30 days
$where .= " AND post_date > \'" . date(\'Y-m-d\', strtotime(\'-30 days\')) . "\'";
return $where;
}
add_filter( \'posts_where\', \'filter_where\' );
$the_query = new WP_Query( array(
\'posts_per_page\' => \'5\',
\'v_sortby\' => \'views\',
\'post_type\' => array( \'post\', \'music\', \'videos\', \'albums\' ),
\'tax_query\' => array(
array(
\'taxonomy\' => \'content\',
\'field\' => \'slug\',
\'terms\' => array( \'indy\' ),
\'operator\' => \'NOT IN\'
)
)
));
remove_filter( \'posts_where\', \'filter_where\' );
// The Loop
while ( $the_query->have_posts() ) :
$the_query->the_post(); ?>
<a class="widget-post-title" href="<?php the_permalink() ?>" rel="bookmark">
<?php the_title(); ?></a>
<a class="thumbnails-link" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"> </a>
<?php endwhile;
/* Restore original Post Data
* NB: Because we are using new WP_Query we aren\'t stomping on the
* original $wp_query and it does not need to be reset.
*/
wp_reset_postdata(); ?>