0

Is there a way in WordPress to use WP_Query and retrieve posts/galleries that have more than 0 metavalues with the key _gallery_image_ids?

Essentially I don't want to display galleries that have no images.

1 Answer 1

1

I believe that a relatively simple meta_query would do it.

$args = array(
    'post_type' => 'post',
    'meta_query' => array(
        array(
            'key' => '_gallery_image_ids',
            'value' => '',
            'compare' => 'EXISTS'
        )
    )
);
$query = new WP_Query( $args );

Reference:

http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.