Timeline for Way to include posts both with & without certain meta_key in args for wp_query?
Current License: CC BY-SA 3.0
11 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
S Aug 26, 2017 at 13:05 | history | suggested | Hector | CC BY-SA 3.0 |
Fix wrong array key name 'surpress' . Correct one is 'subpress'.
|
Aug 26, 2017 at 9:38 | review | Suggested edits | |||
S Aug 26, 2017 at 13:05 | |||||
Apr 13, 2017 at 12:37 | history | edited | CommunityBot |
replaced http://wordpress.stackexchange.com/ with https://wordpress.stackexchange.com/
|
|
Sep 14, 2011 at 16:46 | comment | added | eddiemoya | Thats good to know. However you should have been able to have meta_key do the sorting, and have meta_query do the filtering, simultaneously. I was not saying to not use meta_key, that was just for testing, I was saying to use both. | |
Sep 14, 2011 at 0:01 | comment | added | Michelle | From my understanding (and tests) you actually must use the old meta_key=value or orderby won't work at all (codex.wordpress.org/Class_Reference/…). Luckily I think I've found a way around this altogether - by setting that particular custom field to have a default value of 0. That way the key is always present, and the results come back effectively unsorted. Thanks again for your help!! :) | |
Sep 13, 2011 at 23:04 | comment | added | eddiemoya | So first of all, I'll presume the meta_query worked correctly and retrieved the posts you wanted. My understanding was the meta_query should override meta_key in terms of filtering posts. The link you posted seems to actually confirm what I am saying. "but you can still use the old method of [meta_key] in addition to the meta_query, as these lines indicate how to sort the resulting query. So yes, you might indicate the same meta_key twice." | |
Sep 13, 2011 at 22:40 | comment | added | Michelle | I've tried it, but it seems that orderby only works when you explicitly include meta_key (wordpress.stackexchange.com/questions/10941/…). And my understanding is once meta_key is explicitly named, it automatically screens out any posts without that meta_key. Am I missing something? | |
Sep 13, 2011 at 22:09 | history | edited | eddiemoya | CC BY-SA 3.0 |
added 943 characters in body
|
Sep 13, 2011 at 22:07 | comment | added | eddiemoya | To test this, remove the meta_key from the query all together.That way you wont filter by that meta_key.This should bring you back to everything you want. Now, you need to use meta_query to get that same result (seems silly, i know).So I think you should use multiple meta_queries, both the same except that 'compare' will be 'IN' on one, and 'NOT IN' on the other. I'm not sure how this works pre-3.2, but in 3.2 you can use 'relation' the same way you can in tax_query.So if your on 3.2, your relation should be OR. So you will get any posts that are IN your meta_key OR are NOT IN your meta_key | |
Sep 13, 2011 at 19:43 | comment | added | Michelle | Thanks @eddiemoya! I'd looked at a most of those already but I'm still unclear on how to actually code this. The query currently pulls back all the posts I want except the ones that have no book-in-series meta value. The question is how would I get both the ones with the value (sorted) and the ones without? If you want to see the full context of my archive I had to post it in a separate question here: wordpress.stackexchange.com/questions/28424/… Thank you so much for your time! | |
Sep 13, 2011 at 18:36 | history | answered | eddiemoya | CC BY-SA 3.0 |