I know how to do that in pure SQL but I can’t get WP_Query to nest conditions in the way required.
If it is acceptable, the easiest way to make this work would be to assign an arbitrary far future end date when the data is saved to the database. Something like strtotime("2038-01-01")
.
That is a bit of a hack but Core functions should work and you wouldn’t need to write your own SQL. Using a fixed date like that means that you can easily find and alter the expiration date if 2038 comes around and you find you need to, or you could remove the date if WP_Query
gets patched to handle the kind of query logic you need.
Related Posts:
- Ordering posts by anniversary using only day and month
- How can I query on the year part of a complete date in a custom field?
- Displaying posts with only upcoming dates according their custom field date value
- meta_value_num sort glitch
- Change order of posts
- filter custom field values $min $max
- Ordering posts by custom field named “date” in backend
- WP Query – Is this correct?
- Query post by date (stored custom field meta as yyyymmdd) and differentiate across 12 months
- Meta_query ‘compare’ => ‘LIKE’ not working?
- Filter Query Post by Custom Fields(by date)
- Custom query with orderby meta_value of custom field
- Using meta query (‘meta_query’) with a search query (‘s’)
- Using meta_query, how can i filter by a custom field and order by another one?
- ORDER BY custom field value
- Can I query custom meta data through WP_Query
- Matching Serialized Arrays with meta_query
- query_posts and only show results if a custom field is not empty
- Date, Time, and Timezones
- Trying to perform complex custom field query with order by set to field value
- Is there a way to do multiple ordering on a multiple meta_query?
- Order posts by custom field and if custom field is empty return remaining posts
- order by meta_value serialized array
- Order by custom field date with ASC order
- WordPress Search Custom Meta Field Only
- Calling Specific Pages with wp query Part II
- Loop through two different sets of custom fields
- Localized Date Format for Custom Field
- Slow meta query with multi meta keys
- Using OR in WP_Query negates the “NOT EXISTS” compare
- How to use query_posts() with a date filter on a custom field?
- How can I combine meta_query queries?
- Difference between ‘LIKE’ and ‘IN’ in meta queries
- Display custom post types with custom date field value (before today) & order by custom date field
- Sorting posts by multiple values, combined
- WP_Query display next custom post from today’s date
- Can ordering post list by meta_value cause performance issue?
- Which is best in the following scenario : post_meta vs custom table vs parent/child posts
- WP_Meta_Query causing long-running MySQL queries
- How do I query for a post by custom field?
- how can i use custom field in query post
- using multiple meta_key and meta_value in query_posts
- Complex WP_User_Query call fails on production server
- Query post order by post and desc not working
- How can I sort homepage by a meta value?
- Sorting WordPress Posts via Custom Field Values?
- How make a custom search on backend in WordPress without plugin?
- How to add a new meta key and assign timestamp to posts
- Show 1 post and after a specific date show the next one
- Get content from pages with same meta_key from Database
- How to select posts from multiple categories and metavalues?
- meta_compare seems to be treating values as strings instead of integers as expected
- How to order posts by one custom field and filter them by another one?
- How do I have WP_Query match posts based on search parameter OR meta fields? (rather than search parameters AND meta fields)?
- Alter main archive, to show posts with meta as last
- Meta Query returns wrong number of posts
- Meta Query posts not showing on ending date of custom field
- Use meta_query to get title of associated post
- get posts where a custom field contains a text
- Query_posts with custom field meta value
- Avoiding ACF get_field and returning to core WordPress function
- Unable to get specific value from post meta
- comment meta_query for keys that aren’t yet set
- Sort custom post type by most current date picker
- change order of images attached to post
- Diamond question mark in text after migrating content
- query_posts with meta_value
- Custom search SQL Query to add custom field in result
- tax query between operator like
- How can I change the publish date based on a custom field?
- How show post only from after custom date
- Best way to sort estates and query them (for rent? yes/no. contains office space? yes/no)?
- Is it possible to compare the current time with a custom “start” and “end date
- Get author total post votes from post meta
- Order by custom date field
- Group Posts By Custom Meta Value: Date
- How can I modify my meta_query to work with prices that are stored in the database that contain dollar signs and commas?
- simple fields plugin custom query
- Need to search a custom field (ingredients, one long string per post), but want it to allow phrases/non-exact matches
- Making WP_Query limit results by date before today where date is a meta_query
- multiple meta_query and orderby question
- How to improve my non-unique metadata MySQL entries?
- WP meta_query args not working in function
- Filtering posts by ACF meta query
- Why does my numeric meta query work only on one meta key and not the other?
- Problem with my loops
- meta_query to check all custom fields
- Query multiple meta values at the same time :
- Create Shortcode shows only posts with custom_field meta
- query_posts -> get page_id from custom field
- Admin – Search Events by a custom field
- Thirtieth century date for a post
- Query Posts Via WordPress URL
- Meta_query not filtering posts
- Complex WP_Query Using Post Date And Post Meta
- Filtering posts by WORD in custom field
- Display agents (custom post type) alphabetically, except one who always shows last
- Dynamic background image used in css after selector
- Dynamically update Custom Fields to display new dates
- WP Query Args – search by meta_key or title