Timeline for How to query using a combination of custom_field values?
Current License: CC BY-SA 3.0
16 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Dec 23, 2014 at 22:10 | vote | accept | pixeline | ||
Dec 23, 2014 at 22:07 | history | edited | cybmeta | CC BY-SA 3.0 |
deleted 224 characters in body
|
Dec 23, 2014 at 21:56 | comment | added | pixeline | Let us continue this discussion in chat. | |
Dec 23, 2014 at 21:53 | comment | added | cybmeta |
See edited answer. It should return posts with bjab_event_date_start_id >= today (not matter which bjab_event_date_end_id it has; it is upcoming event or current if = today) OR posts with bjab_event_date_start_id < today AND bjab_event_date_end_id EXISTS (is set) AND >= today (it has a start date in the past and a end date in the future). Note that I need the meta field code because I think the data format for date can not be correct.
|
|
Dec 23, 2014 at 21:51 | history | edited | cybmeta | CC BY-SA 3.0 |
deleted 349 characters in body
|
Dec 23, 2014 at 21:48 | comment | added | cybmeta | Also, can you post the date format on your custom field? I think you are not using it corretly. You are trying to compare numeric values but you are using "Y-m-d" date format. Not sure if I don't see the meta field code. | |
Dec 23, 2014 at 21:47 | comment | added | pixeline | Sorry for my unclear comment, i'll fix it immediatly. To be clear: if a post has no event_end_date_id set, either its event_start_date_id is past, so it should not be selected, or is upcoming/current, in which case it should be selected. | |
Dec 23, 2014 at 21:27 | history | edited | cybmeta | CC BY-SA 3.0 |
added 233 characters in body
|
Dec 23, 2014 at 21:21 | comment | added | cybmeta |
Wait. If a post has not event_end_date_id set, how do you want to handle it? Please, think again about the date conditionals and think about any possible scenarios. In your last question update your code says: "retur post with bjab_event_date_start_id < today AND event_end_date_id <= today AND event_end_date_id != "" ; that obviously doesn't match, event_end_date_id can not be <= today and != "" at the same time. See my suggestion with "NOT EXIST".
|
|
Dec 23, 2014 at 21:17 | comment | added | cybmeta |
Maybe you can include a nested meta query with NOT EXISTS as comparison parameter. I will edit the answer in a moment with an example.
|
|
Dec 23, 2014 at 21:16 | comment | added | pixeline | I have updated my question with the current code, in which I tried to address the case where event_end_date_id is empty. No dice: i don't get any result anymore. I'm really having a hard time understanding this syntax. | |
Dec 23, 2014 at 21:07 | comment | added | pixeline | I think the problem may occur because many posts do not have any event_end_date_id set. I guess the comparison accepts to consider that today >= '' | |
Dec 23, 2014 at 21:05 | comment | added | pixeline | sorry, my mistake: category is fine. Still, the parameters don't seem to matter: all posts in category are displayed, no matter the event_date_start or _end value. I'll update my question with the current code. | |
Dec 23, 2014 at 20:48 | comment | added | cybmeta |
That is strange. Adding a meta_query shouldn't affect to category parameter. Check that the category slug is correct and try with and without the meta_query . And it is not a good idea include category or any other non-meta query arguments in the meta_query array.
|
|
Dec 23, 2014 at 20:17 | comment | added | pixeline | I've updated to 4.1 and tried your suggestion: it shows all posts (not only those in the category "private"). Why is that? I tried also specifying the category as part of each meta value array. Thanks a lot for current_time(), i was unaware of its existence! | |
Dec 23, 2014 at 19:05 | history | answered | cybmeta | CC BY-SA 3.0 |