2016-05-22 59 views
0

我正在使用wp-types插件來管理WordPress網站上的自定義帖子類型。爲了顯示文章類型列表,我使用下面的代碼:php wp-types顯示分類

<?php 
     $args = array(
      'posts_per_page' => 20, 
      'post_type' => 'products', 
      'orderby' => 'meta_value', 
      'post_count' => -1 
     ); 
     $query = new WP_Query($args); ?> 

     <?php while ($query->have_posts()) : $query->the_post(); $categories = get_the_category(); ?> 

     <div>The custom post</div> 



     <?php endwhile; wp_reset_postdata(); ?> 

有我的方式,我可以修改這從(在這種情況下),特定產品的分類顯示一個列表?

乾杯

回答

2

可以,它會是這個樣子:

<?php 
    $args = array(
     'posts_per_page' => 20, 
     'post_type' => 'products', 
     'orderby' => 'meta_value', 
     'post_count' => -1, 
     'tax_query' => array(
      array(
       'taxonomy' => 'example', // get posts in the 'example' taxonomy 
       'field' => 'slug', // that have a slug that matches 
       'terms' => 'test', // any of the terms listed 
      ), 
     ), 
    ); 
    $query = new WP_Query($args); ?> 

    <?php while ($query->have_posts()) : $query->the_post(); $categories = get_the_category(); ?> 

    <div>The custom post</div> 



    <?php endwhile; wp_reset_postdata(); ?> 

檢查出每個參數的詳細信息,WP_Query文檔的Taxonomy section