I want to exclude every post with a specific value of a custom meta field. The problem is, that not every posts has this meta field.
My code looks like this (excerpt of the working loop):
// WP_Query arguments
$args = array (
'post_parent' => $parentid,
'orderby' => 'menu_order',
'order' => 'ASC',
'post_type' => array( 'page' ),
'meta_query' => array(
array(
'key' => 'hide',
'value' => 1,
'compare' => '!='
)
)
);
Not every posts uses the field "hide". Some posts giving back a NULL. So I think, the loop isn't working because of that?!
Is this correct? Is it necessary that every posts has a value for that key?
Another way to do it:
// WP_Query arguments
$args = array (
'post_parent' => $parentid,
'orderby' => 'menu_order',
'order' => 'ASC',
'post_type' => array( 'page' ),
'meta_query' => array('0' => array('key' => 'hide', 'value' => '1', 'compare' => 'NOT EXISTS')
)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With