meta_query without 'key' results in compare of '!=', 'NOT LIKE' not wo
-
Running a new WP_Query on a template page.
I’m trying to return a long list of posts from four different custom post types, as well as 5 different taxonomies, a couple of which have limited terms.
I’m filtering one of the post types by a custom field that only that
post type has; none of the others have it. That custom field is:‘has_page’
And has a value of either
‘yes’ or ‘no’
Initially setting the $args up with the ‘key’ value wound up filtering out all the other post types that do not have that key. So I pulled the ‘key’ from the array, and set the compare to !=, and then to “NOT LIKE”.
'meta_query' => array( array( //'key' => 'has_page', 'value' => 'no', 'compare' => '!=', ) ),
Neither of these worked. Every post from all post types are returned.
However, if I set the ‘compare’ to ‘=’ or ‘LIKE’, it does wind up filtering the posts and returning only the post type that has a value of no, or returning the post type with a value of ‘yes’. But everything else gets dropped.
How do I filter this subset of posts that have that custom field with that specific value, as well as include all other posts that don’t have that custom field? Is there a way to apply a meta_query to a specific post type?
Here’s the complete list of args, maybe something is conflicting?
$args=array( 'tax_query' => array ( 'relation' => 'OR', array( 'taxonomy' => 'styles', 'terms' => $stylesterms, ), array( 'taxonomy' => 'materials', 'terms' => $materialsterms, ), array( 'taxonomy' => 'venues', 'field' => 'slug', 'terms' => $venuesterms, 'operator' => 'NOT IN', ), array( 'taxonomy' => 'decades', 'terms' => $decadessterms, ), array( 'taxonomy' => 'exhibitions', 'terms' => $exhterms, ), ), 'posts_per_page' => 15, 'paged' => $paged, 'ignore_sticky_posts' => 1, 'post_type' => array('location','people','comparative','woa'), 'orderby' => 'title', 'order' => 'DESC', 'meta_query' => array( array( //'key' => 'has_page', 'value' => 'yes', 'compare' => '!=', ) ), );
- The topic ‘meta_query without 'key' results in compare of '!=', 'NOT LIKE' not wo’ is closed to new replies.