Forums › Forums › Search & Filter Pro › Post Meta OR option?
Tagged: field relationship, meta_query, or, post meta, post meta arguments
- This topic has 11 replies, 2 voices, and was last updated 8 years, 5 months ago by Anonymous.
-
Anonymous(Private) June 21, 2016 at 9:47 pm #49094
I currently have two different sorts of post type: events, which are displayed (or not) based on date, and posts which are displayed (or not) based on a meta radio field (set to either Published – value1, or archived – value2).
Because events doesn’t use this field, I’m running into a problem: filtering my normal posts based on this field also excludes my events post type, where the field doesn’t exist so can’t have the value I’m looking for.
The usual way I get around is this is using “relation: OR” to return posts where the value is value1 OR where the meta field doesn’t exist, which looks something like this:
$meta_query = array( 'relation' => 'OR', array( 'key' => 'devvy_status', 'value' => 'value1', 'compare' => '==', ), array( 'key' => 'devvy_status', 'compare' => 'NOT EXISTS', ) );
I’m trying to achieve the same result in the plugin and can’t get it to work.
Thus far, I’ve set the first Post Meta field to:
devvy_status char = (equals) value1
And the second to:
devvy_status char not exists
And changed the field relationships option to “OR”.
This just seems to break the search entirely, and it returns absolutely nothing :/
If I get rid of that second argument it works great, it just doesn’t include my events, which don’t have that meta_field.
Any ideas how to solve this? Is there something I’ve set wrong?
Anonymous(Private) June 22, 2016 at 3:42 pm #49184Okay!
So, if you look at the current search page: http://devvy.site/search/ you can see it’s returning a nice list of all my posts, for all my various post types.
However, I want it to exclude posts marked as “archived” using the above meta_query.
If you go into Search & Filter settings for my “Search Archive” form and add back my arguments (as above), it breaks the search page and returns no results.
The behaviour I’d expect is for it to return all the posts EXCEPT “This is a test post” (at the bottom), which is currently the only marked as archived.
Yell if that doesn’t make sense!
Trevor(Private) July 4, 2016 at 3:17 pm #50145Jon
This one escaped me, does it still need my action? I spoke to Ross and currently the way the logic works what you want can’t work. In effect, what you need is a way of testing is a field value has NOT been set or is empty. At least, that’s what Ross and I read into what you asked for. If we are right, this will need to go into feature requests and join that long line of features to be added.
Anonymous(Private) July 6, 2016 at 11:52 am #50310It does, unfortunately.
Yeah, that’s right. I need a way of displaying posts with a certain meta value OR that don’t have that meta field.
So that’s not what the current args are setup for? There IS a no exists option, I’d assumed that this was what it was for.
That’s really disappointing.
I’ll add it to the feature request list, but my client isn’t going to be happy that it doesn’t do what we thought it did.
Thanks anyway, Trevor.
-
AuthorPosts