2016-11-25 70 views
0

我一直在試圖列出我的自定義類型'電影'與自定義分類體裁與戲劇值。 我已經嘗試了幾種解決方案,但至今我失敗了。如何列出自定義帖子類型'電影'的類型'恐怖'

<?php 

$args = array(
'post_type'  => 'movies', 
'tax_query'  => array(
    array(
    'taxonomy' => 'genre', 
    'field'  => 'term_id', 
    'terms'  => 'drama' 
    ) 
) 
); 

$drama = new WP_Query($args); 

if ($drama->have_posts()) : while ($drama->have_posts()) : $drama->the_post(); ?> 


<h4><?php echo the_title(); ?></h4> 

<?php endwhile; ?> 

<?php else : echo '<p>NO CONTENT FOUND</p>'; ?> 

<?php wp_reset_postdata(); ?> 

<?php endif; ?> 

希望有人可以在這個問題上提出一些看法。

史蒂芬

回答

0

field參數是錯誤的,你的情況,你需要將其設置爲slug戲劇不是term_id

$args = array(
    'post_type'  => 'movies', 
    'tax_query'  => array(
     array(
     'taxonomy' => 'genre', 
     'field'  => 'slug', 
     'terms'  => 'drama' 
    ) 
    ) 

);

希望它的作品!

+0

工作一種治療...自我教學wordpress有其弊端。 – scottiescotsman

+0

由於某種原因我的分頁不斷顯示第1頁lol – scottiescotsman

+0

添加'posts_per_page'參數以增加結果數量。 – Benoti