具有3个条件的Wordpress元查询

时间:2014-09-25 12:43:15

标签: php mysql wordpress

我正在制作一个自定义的wordpress主题,并且对php& MySQL但不太适用于wordpress API,所以我想知道你们中的一个可爱的人是否可以帮助我。基本上我有这个问题:

$args = array(
        'post_type' => 'any',
        'orderby' => 'post_date',
        'posts_per_page' => '3',
        'post_status' => 'publish',
        'meta_query' => array(
                'relation' => 'OR',
                array(
                    'key' => 'catwalk_reports_feature_on_home_page',
                    'value' => '1',
                    'compare' => '='
                    ),
                array(
                    'key' => 'product_service_feature_on_home_page',
                    'value' => '1',
                    'compare' => '='
                    ),
                array(
                    'key' => 'wedding_tips_feature_on_home_page',
                    'value' => '1',
                    'compare' => '='
                    ),
            ),
    );


$the_query = new WP_Query( $args );

哪个失败了!:(

这似乎是因为我有3个数组,当执行查询时如下:

$args = array(
        'post_type' => 'any',
        'orderby' => 'post_date',
        'posts_per_page' => '3',
        'post_status' => 'publish',
        'meta_query' => array(
                'relation' => 'OR',
                array(
                    'key' => 'catwalk_reports_feature_on_home_page',
                    'value' => '1',
                    'compare' => '='
                    ),
                array(
                    'key' => 'product_service_feature_on_home_page',
                    'value' => '1',
                    'compare' => '='
                    ),
            ),
    );


$the_query = new WP_Query( $args );

没有错误,一切都按预期工作....

有什么想法吗?

提前致谢;

1 个答案:

答案 0 :(得分:0)

你可以这样试试吗:

$args = array(
  'post_type' => 'any',
  'posts_per_page' => get_option('of_an_nr20'),
  'meta_query' => array(
  'relation' => 'OR',
       array('key' => 'iframe'),
       array('key' => 'video'),
       array('key' => 'videoflv')
  )
);

$gab_query = new WP_Query();$gab_query->query($args);
while ($gab_query->have_posts()) : $gab_query->the_post();