自定义分类WP_Query

thi*_*guy 5 php mysql wordpress

我正在尝试显示具有自定义分类的自定义帖子类型,但我没有任何运气.什么都没有出现.我感谢任何帮助.

帖子类型=图库

自定义分类标准slug = photoarea

'photoarea'我想显示=第四

在此输入图像描述

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

?> 
Run Code Online (Sandbox Code Playgroud)

Jot*_*nan 1

如果我的理解是正确的,您需要使用以下代码获取自定义分类法,而不是field必须使用term第四个中的帖子

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

?> 
Run Code Online (Sandbox Code Playgroud)