php wp类型显示分类法
我正在使用wp类型插件管理wordpress站点上的自定义帖子类型。要显示帖子类型列表,我使用以下代码:php wp类型显示分类法,php,wordpress,custom-post-type,taxonomy,Php,Wordpress,Custom Post Type,Taxonomy,我正在使用wp类型插件管理wordpress站点上的自定义帖子类型。要显示帖子类型列表,我使用以下代码: <?php $args = array( 'posts_per_page' => 20, 'post_type' => 'products', 'orderby' => 'meta_value', 'post_count' => -1
<?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_查询文档的。如果可以,它将如下所示:
<?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_查询文档的