Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.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 自定义wordpress查询不工作_Php_Wordpress - Fatal编程技术网

Php 自定义wordpress查询不工作

Php 自定义wordpress查询不工作,php,wordpress,Php,Wordpress,“archive.php”文件中有以下代码(来自当前活动主题): list($f_categu_name)=分解('/',获取父类($cat)); 如果($f_categ_name==“X_categ”){ $paged=(get_query_var('paged'))?get_query_var('paged'):1; $args=数组( “post_type”=>“post”, “类别名称”=>单一类别标题(“”,错误), “meta_key”=>“x_categ_type”, 'order

“archive.php”文件中有以下代码(来自当前活动主题):

list($f_categu_name)=分解('/',获取父类($cat));
如果($f_categ_name==“X_categ”){
$paged=(get_query_var('paged'))?get_query_var('paged'):1;
$args=数组(
“post_type”=>“post”,
“类别名称”=>单一类别标题(“”,错误),
“meta_key”=>“x_categ_type”,
'orderby'=>'meta_value',
“订单”=>“ASC”,
“paged”=>$paged,
);
//取得成果
$thew_query=newwp_query($args);//循环
?>
我有两个类别:A(15篇博文)和B(7篇博文),它们有相同的父类别(比如说X_CATEG),所以基本上我运行相同的代码,但是
$the_query->have_posts()
对于一个类别返回true,对于B类别返回false为什么?


使用$GLOBALS['wp\u query']->请求我能够调试执行的查询,并且两个查询(对于类别A和B)都返回了所有帖子ID。

wp\u查询
参数中,
类别名称
将是类别
slug
而不是类别标题

single_cat_title
如果查询类别或标记存档,函数将返回页面标题

因此,您应该在WP_查询参数中使用category
slug
,而不是category
title

希望这会有所帮助。

谢谢。这就是问题所在(稍作调整)。
list($f_categ_name) = explode('/', get_category_parents($cat));
            if ( $f_categ_name == "X_CATEG") {
                $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                $args = array(
                    'post_type' => 'post',
                    'category_name' => single_cat_title( '', false ),
                    'meta_key' => 'x_categ_type',
                    'orderby' => 'meta_value',
                    'order' => 'ASC',
                    'paged' => $paged,
                );
                // get results
                $the_query = new WP_Query( $args );                 // The Loop
                ?>
                <?php if( $the_query->have_posts() ): ?>