The following code fetches posts with the meta key home telephone numbers.
$metas = '';
$args = array(
'numberposts' => 1,
'post_type' => 'electors',
'orderby' => 'post_date',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'wpcf-home_telephone_number',
'value' => '0',
'compare' => '>'
)
)
);
$canvassing = get_posts( $args );
I want to add another meta to look for. The problem is that this meta may not exist on all posts. I want to get posts that either don't have the meta key or don't have a value for it.
array(
'key' => 'wpcf-success',
'value' => ''
)
This code will only get posts that have the key without a value. I also want posts that do not have this key at all.
I tired this add_post_meta($post->ID, 'wpcf-success', '', true); but since we have not fetched the posts there is no post ID yet.