带 redux 选项的 wordpress wp_query 不工作

wordpress wp_query with redux option is not working

我希望能够从主题选项面板中选择一个类别,它会显示该特定类别的所有帖子。

所以我已经像这样设置了我的 wp_query:

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

&我的主题选项面板代码是:

'id' => 'featured_rcp',
'type' => 'select',
'data' => 'categories',
'multi' => true,
 'title'  => __('Recipe Category.', 'imd'),
'subtitle'   => __('Recipe Category for home page.', 'imd')

但它显示所有类别的帖子,而不是我在选项面板中 select 的帖子。虽然每页的帖子工作正常。我不太精通PHP,所以请有人告诉我我哪里做错了。

WP_Query的类别参数错误,应该是catcategory_name,具体取决于值的类型。

查看 WP_Query 的 Category Parameters 并选择您需要的。

尝试:

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;

为我工作。