Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
meta_query to search post without custom field (no matter whether its empty or doesn't exist at all [WordPress]
$getposts = get_posts( array(
'numberposts' => -1, // тоже самое что posts_per_page
'post_type' => 'post',
'post_status' => 'any',
'fields' => 'ids',
'meta_query' => array(
'relation' => 'OR',
'key' => 'custom_field',
'compare' => 'NOT EXISTS',
'value' => '', //ignored but necessary
'key' => 'custom_field',
'value' => array(''),
'compare' => 'IN',
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.