簡體   English   中英

WP_QUERY:按標簽返回帖子,按帖子格式過濾

[英]WP_QUERY : Return posts by tags , filtered by post formats

我有以下代碼片段,應該按標記返回與當前帖子相關的6個帖子,而這6個帖子應該是具有視頻帖子格式分類法的帖子:

if('artists' == get_post_type()){
    $taxs = wp_get_post_tags($post->ID);
    $name = the_title();
    if($taxs){
        $tax_ids = array();
        foreach ($tax_ids as $individual_tax){
            $tax_ids[] = $individual_tax->term_id;
        }
        gs = array(
        'post_type' =>'post',
        'tag__in'=> $tax_ids,
       'tax_query' =>array(                         
                            array(
                                'taxonomy' => 'post_format',
                                'field' => 'slug',
                                'terms' => array('post-format-video')
                                ),
                        ),
        'post__not_in' => array($post->ID),
        'posts_per_page' => 6,
        'ignore_sticky_posts' => 1,
        );
     $video_query = new WP_QUERY($args);
    // other code comes here .........

問題是,當我運行查詢時,它將返回所有具有視頻帖子格式的帖子,而不是那些具有相關標簽作為當前帖子被查看的帖子。 請幫我解決這個問題。

讓我舉一個例子:當前帖子有一個名為“ oranges”的標簽。 在相關的帖子部分中,我希望它顯示也有一個名為oranges的標簽的帖子,但僅顯示具有視頻帖子格式分類法的帖子。

您的foreach循環應為:

foreach ($taxs as $individual_tax)

並不是:

foreach ($tax_ids as $individual_tax)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM