Php 自定义分类WP\u查询
我试图显示一个具有自定义分类法的自定义帖子类型,但我没有任何运气。什么也没有出现。谢谢你的帮助 职位类型=画廊 自定义分类slug=photoarea 我要显示的“photoarea”=第四个Php 自定义分类WP\u查询,php,mysql,wordpress,Php,Mysql,Wordpress,我试图显示一个具有自定义分类法的自定义帖子类型,但我没有任何运气。什么也没有出现。谢谢你的帮助 职位类型=画廊 自定义分类slug=photoarea 我要显示的“photoarea”=第四个 <?php $args = array( 'post_type' => 'gallery', 'tax_query' => array( array(
<?php
$args = array(
'post_type' => 'gallery',
'tax_query' => array(
array(
'taxonomy' => 'photoarea',
'field' => 'fourth',
)
),
'posts_per_page' => 10,
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
the_post_thumbnail();
endwhile; endif;
wp_reset_query();
?>
如果我的理解是正确的,您需要使用以下代码获得自定义分类, 你必须使用
术语而不是字段
来获得第四个职位
<?php
$args = array(
'post_type' => 'gallery',
'tax_query' => array(
array(
'taxonomy' => 'photoarea',
'field' => 'slug',
'terms' => 'fourth'
)
),
'posts_per_page' => 10,
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
the_post_thumbnail();
endwhile; endif;
wp_reset_query();
?>
您可以使用以下代码段:
$the_query = new WP_Query( 'post_type=gallery&photoarea=fourth');
然后是你的while循环。你需要“field”=>“slug”和“terms”=>“fourth”来完成这项工作,而不是“term”。
$args = array('post_type' => 'gallery','posts_per_page'=>'-1','tax_query' => array(array(
'taxonomy' => 'photoarea',
'field' => 'term_id',
'terms' => $your_term_id,
),
),
);