Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.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 带有redux选项的wordpress wp_查询不工作_Php_Wordpress_Redux Framework - Fatal编程技术网

Php 带有redux选项的wordpress wp_查询不工作

Php 带有redux选项的wordpress wp_查询不工作,php,wordpress,redux-framework,Php,Wordpress,Redux Framework,我想有能力从主题选项面板中选择一个类别&它将显示该特定类别中的所有帖子 因此,我将wp_查询设置为: <?php $featured_rcp= $redux_imd['featured_rcp']; $catquery = new WP_Query(array( 'category' => $featured_rcp, 'posts_per_page' => 1 )); while($catquery->have_posts()) : $catquery->th

我想有能力从主题选项面板中选择一个类别&它将显示该特定类别中的所有帖子

因此,我将wp_查询设置为:

<?php
$featured_rcp= $redux_imd['featured_rcp'];
$catquery =  new WP_Query(array(
'category' => $featured_rcp,
'posts_per_page' => 1
)); 
while($catquery->have_posts()) : $catquery->the_post();
 ?>

但它显示了所有类别的帖子,而不是我从选项面板中选择的那个。虽然每页的帖子都很好。我不太精通PHP,所以请有人告诉我我哪里做错了。

WP\u查询的category参数是错误的,它应该是
cat
category\u name
,这取决于值的类型

检查WP_的查询并选择您需要的查询。

尝试:

global $redux_imd;

$featured_rcp = !empty($redux_imd['featured_rcp']) ? $redux_imd['featured_rcp'] : array();

if ( !empty($featured_rcp) ) :

    query_posts( array( 'cat' => $featured_rcp, 'posts_per_page' => 1, 'orderby' => 'date', 'order' => 'DESC' ) );

    if (have_posts()) : 
         while (have_posts()) : the_post();
             the_title()
         endwhile;
    else :
        _e('No post found!');
    endif; 

endif;

为我工作。

您是否验证了
$redux\u imd['featured\u rcp']
不是空的?请在循环之前打印出来。不,它不是空的,它返回:3有趣的是,我以前使用过
cat
category\u name
,但不起作用。这次
cat
正在工作。
global $redux_imd;

$featured_rcp = !empty($redux_imd['featured_rcp']) ? $redux_imd['featured_rcp'] : array();

if ( !empty($featured_rcp) ) :

    query_posts( array( 'cat' => $featured_rcp, 'posts_per_page' => 1, 'orderby' => 'date', 'order' => 'DESC' ) );

    if (have_posts()) : 
         while (have_posts()) : the_post();
             the_title()
         endwhile;
    else :
        _e('No post found!');
    endif; 

endif;