带有redux选项的wordpress wp_query不起作用

时间:2021-01-11 16:38:11

I want to have the ability to choose a category from theme option panel & it ll show all the posts from that exact particular category.

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

so I have setup my wp_query like this:

所以我设置了这样的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();
 ?>

& my theme option panel code is:

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

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

but it showing posts from all categories, not the one which I select from option panel. though posts per page is working fine. I'm not well versed in PHP, so please some one tell me where I'm doing wrong here.

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

2 个解决方案

#1


The category parameter of the WP_Query is wrong, it should be cat or category_name, depending on the type of the value.

WP_Query的category参数是错误的,它应该是cat或category_name,具体取决于值的类型。

Check out the Category Parameters of WP_Query and choose which one you need.

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

#2


Try:

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;

Working for me.

为我工作

#1


The category parameter of the WP_Query is wrong, it should be cat or category_name, depending on the type of the value.

WP_Query的category参数是错误的,它应该是cat或category_name,具体取决于值的类型。

Check out the Category Parameters of WP_Query and choose which one you need.

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

#2


Try:

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;

Working for me.

为我工作