I'm trying to set up a query filter for a view using one of two criteria- I want to display posts that have either a value of 1 in Field A, OR a value of 2 in Field B. This doesn't seem to be possible! When I add an additional filter, I don't have the option of indicating AND or OR, it seems like by default the filter will select posts that have both a value of 1 in Field A and a value of 2 in Field B. Is there any way around this problem? I know that when I'm using fields conditionally in a view or content template, I have a choice of AND/OR when evaluating conditions. So it seems like I should have the same options when querying posts in the first place.
Hi, there's an option to choose "AND" or "OR" to link the custom field filters. Here's a screenshot showing the AND / OR option in the Query Filter panel. You can only choose one, so complex combinations that require different relationships between various fields are not possible in the GUI. That type of custom filter would require custom code using the wpv_filter_query API. If I've misunderstood the request, please let me know.
That is really bizarre... I don't have that option! See screenshot.
Right, there's only one custom field filter in your screenshot so it won't appear until you add another custom field filter. The post date filter above doesn't count - the AND/OR is specifically for custom field filters only.
Hmmm... so there is no way to choose AND/OR for any other filter besides custom fields? What I'm trying to accomplish is show a list of posts that either were published more than six months ago (the date query) OR posts that were published within the past six months, but have been "archived" (as indicated by a value in a custom field).
No, unfortunately there is no way to set up that type of filter using the GUI in wp-admin. A combined publish date and custom field conditional will require custom PHP code using the wpv_filter_query or wpv_filter_query_post_process APIs.
We have documentation available for those APIs here: https://toolset.com/documentation/programmer-reference/views-filters/
You might be able to get around this restriction by using conditional HTML instead of Query Filters. For example, you could remove the two Query Filters and add a conditional around each item in the loop that checks to see if the post date is older than 6 months ago, OR if the post custom field value is set. This approach works best when your View is unpaginated, because posts hidden by the conditional will still count towards the number of posts in a page of results. In other words, if a page of results should show 10 items but 3 items in the current page are hidden by the conditional, only 7 items will appear in the results of that page.
Thanks, this worked perfectly, I created a shortcode for the Unix timestamp 6 months ago and am evaluating that in my conditional statement.