Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there a way to filter posts by featured image when initialising a WP_Query object?

Example

$my_query = WP_Query(array("has_thumbnail"=>true));

or, more ideally

$my_query = WP_Query(array("has_thumbnail_size"=>"custom_size"));
share|improve this question
add comment

1 Answer

Technically featured image is custom field with name _thumbnail_id that holds attachment ID. So you can easily query with something like:

$args = array(
    'meta_query' => array(
        array(
            'key' => '_thumbnail_id',
        )
    )
 );
$query = new WP_Query( $args );

Size on other hand is attribute of that attachment and not post itself. You will need to loop through attachment and get sizes they have (if I remember right it should be in data returned by wp_get_attachment_metadata()).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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