GET_NEXT_POST设置类别

时间:2016-04-11 作者:user668499

是否可以在Wordpress中设置get\\u next\\u post中使用的类别?

我有一个可以有多个类别的帖子。

在单曲上。php页面显示我想显示的下一篇和上一篇文章。

我想从单曲中选择一个类别。php那么如何在get\\u next\\u post中使用它呢

    $the_cat = \'latest\';

    $next_post = get_next_post($in_same_term = true, $excluded_terms = \'\', $taxonomy = $the_cat); 

1 个回复
SO网友:zipkundan

Try this:

$the_cat = \'latest\';
$term_args = array(\'orderby\' => \'term_id\', \'order\' => \'ASC\', \'fields\' => array(\'term_id\', \'slug\'));
$terms = wp_get_post_terms( $post->ID, \'category\', $term_args );
foreach($terms as $term){
    if($term->slug !== $the_cat){
        $terms_to_exclude .= $term->term_id.\',\';
    }
}
$next_post = get_next_post($in_same_term = true, $excluded_terms = $terms_to_exclude, $taxonomy = \'category\');