Question

so as the questions states, what im trying to accomplish is to fetch only the posts that do not have a featured image set. i tried looking through the docs and i noticed you can use the - symbol to exclude something from your argument, but that isn't working for me. Is there something else i can do in my query args to achieve this? thanks for your help!

$mediaargs = array(
        'post_type' => 'media',
        'posts_per_page' => 1,
        'paged' => $paged,
        'order' => 'DESC',
        'orderby' => 'modified',
        'meta_key' => '-_thumbnail_id',
    );
Was it helpful?

Solution

$mediaargs = array(
        'post_type' => 'media',
        'posts_per_page' => 1,
        'paged' => $paged,
        'order' => 'DESC',
        'orderby' => 'modified',
        'meta_query' => array(
            array(
                'key' => '_thumbnail_id',
                'compare' => 'NOT EXISTS'
            )
        ),
    );
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top