php wp-types 显示分类法

php wp-types display taxonomy

我正在使用 wp-types 插件来管理 wordpress 网站上的自定义 post 类型。要显示 post 类型的列表,我使用以下代码:

<?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(); ?> 

有什么方法可以修改它以显示(在这种情况下)产品的特定分类法的列表?

干杯

可以,它看起来像这样:

<?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 了解每个参数的更多信息。