Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 自定义分类WP\u查询_Php_Mysql_Wordpress - Fatal编程技术网

Php 自定义分类WP\u查询

Php 自定义分类WP\u查询,php,mysql,wordpress,Php,Mysql,Wordpress,我试图显示一个具有自定义分类法的自定义帖子类型,但我没有任何运气。什么也没有出现。谢谢你的帮助 职位类型=画廊 自定义分类slug=photoarea 我要显示的“photoarea”=第四个 <?php $args = array( 'post_type' => 'gallery', 'tax_query' => array( array(

我试图显示一个具有自定义分类法的自定义帖子类型,但我没有任何运气。什么也没有出现。谢谢你的帮助

职位类型=画廊

自定义分类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();

?> 


如果我的理解是正确的,您需要使用以下代码获得自定义分类, 你必须使用
术语而不是
字段
来获得第四个职位

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