Quantcast
Channel: Question and Answer » meta-query
Viewing all articles
Browse latest Browse all 36

How to use meta_query to check if a meta field has something set?

$
0
0

(WordPress 4.3.1)

I’m running a custom loop and only want to include posts that have file uploaded to a custom field: audio_file.

I have tried many solutions around the web and so far nothing works.

Can I use meta_query to check if a key has a value?

Here is my current attempt:

 global $post;      

 $args = array(
    'post_type'      => array (
                        'podcast',
                        'event',
                        ),
    'posts_per_page' => 10,
    'post_status'    => 'publish',     
    'paged'          => get_query_var( 'paged' ),
    'meta_query'     => array (
                            'key' => 'audio_file',
                            'value' => '' ,
                            'compare' => '!=',
                            //'type'    => 'date',
                             ),
    );

    global $wp_query;

    $wp_query = new WP_Query( $args );

    if ( have_posts() ) { while ( have_posts() ) { the_post(); 

The intended result here is to display posts where ‘audio_file’ is not empty.

Thanks.
(WordPress 4.3.1)


Viewing all articles
Browse latest Browse all 36

Trending Articles