WordPress Meta Query with 3 Conditions

I am working on a custom wordpress theme and have a pretty good grip on php & MySQL but less so on wordpress API so I’m wondering if one of you lovely people can help me out. Essentially I have this query:

$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 );

Which fails !:(

Read More

This seems to be because I have 3 arrays, when the query is performed like so:

$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 );

No errors, everything works as expected….

Any ideas?

Thanks in advance;

Related posts

Leave a Reply

1 comment

  1. can you try it this way:

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