【问题标题】:WP_query category__in array only pulls from first category idWP_query category__in 数组仅从第一个类别 id 中提取
【发布时间】:2015-03-09 18:03:22
【问题描述】:

我正在尝试获取以下类别(关系 OR)中帖子的所有帖子 ID:10、11、12、13、14 具有某些额外属性。然而,我的问题在于类别。

我的 wp_query 的 args 数组如下:

$args = array(
                        'orderby' =>'ID',
                        'post_type' => 'post',
                        'post_status' => 'publish',
                        'posts_per_page' => -1,
                        'category__in' => array('10','11','12','13','14'),
                        'meta_query' => array( 
                                    'relation' => 'AND',
                                    array(
                                     'key' => 'joke_type',                 
                                     'value' => $type,                 
                                     'type' => 'CHAR',                 
                                     'compare' =>  '='
                                 ),
                                     array(
                                         'key' => 'joke_rating',
                                         'value' => 3,
                                         'type' => 'SIGNED',
                                         'compare' => '>='
                                     )
                         ),
                         'fields' => 'ids' 
                );

这只会让我从类别 10(或我在数组中首先放置的任何 ID)中获取帖子。我也试过:'category__in' => '10,11,12,13,14''category' => '10,11,12,13,14''cat' => '10,11,12,13,14' 都一样。

知道为什么会发生这种情况吗?

【问题讨论】:

    标签: categories wordpress


    【解决方案1】:

    category__in 数组中的类别 ID 应该是整数而不是字符串。

    变化:

    'category__in' => array('10','11','12','13','14'),
    

    收件人:

    'category__in' => array( 10, 11, 12, 13, 14 ),
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-09
      • 2022-08-10
      • 2016-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-27
      相关资源
      最近更新 更多