Hello @varro,
Try to add the compare key as per WP_Query and Custom Field Parameters instructions.
The EXISTS value can solve your issue.
$query->set('compare', 'EXISTS');
compare
is not a parameter. If you used meta_compare
, which is a parameter along with ‘EXISTS’, you would get what you already have. That would basically be the default that you are already dealing with. So that will NOT solve the issue. It won’t change anything. at all.
Unfortunately. It looks like there are three possible solutions to this, but they are not just a simple setting to your base query.
- Make sure every post has that meta_key with at least an empty value.
- Multiple queries, one where you get the posts in which the
meta_value
is 'something'
, and one where the meta_value
is NOT 'something'
.
- Use a custom Left Join and Order By query. Something like this. Though I have not tried this specific solution, I have done something like it a while back.
Link: http://wordpress.stackexchange.com/a/141367/11966
-
This reply was modified 8 years ago by Jupitercow. Reason: code marks