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?
- Query Posts or Get Posts by custom fields, possible?
- ORDER BY custom field value
- Can I query custom meta data through WP_Query
- Add custom fields to search
- SELECT max(meta_value) FROM wp_postmeta WHERE meta_key=’price’… stops working when value is over 999
- Matching Serialized Arrays with meta_query
- Meta Query with AND & OR?
- query_posts and only show results if a custom field is not empty
- Filter archive.php by custom meta
- 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 by custom field date?
- 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
- Compare meta_query decimals not working right
- Calling Specific Pages with wp query Part II
- Loop through two different sets of custom fields
- Query on custom field count?
- 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?
- Order by value in serialized custom field
- Which is best in the following scenario : post_meta vs custom table vs parent/child posts
- WP_Meta_Query causing long-running MySQL queries
- Author Page Custom Query WHERE author OR [post meta value] OR [post meta value]
- How do I query for a post by custom field?
- meta query not showing any results?
- Sorting posts by custom fields in meta_query
- meta_query for a string inside a meta field containing a comma-separated list
- Order by custom field value not working for acf date 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?
- Meta query with timestamp using WP_query
- Orderby custom field meta value ASC and then by date DESC
- Order query by meta_value with multiple custom fields
- 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
- WP 3.1 meta_query for multiple custom field values
- 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?
- Fetch Record based on meta key dates
- How do I have WP_Query match posts based on search parameter OR meta fields? (rather than search parameters AND meta fields)?
- how to make members list directory through wordpress post custom meta key.
- Get posts with same meta value as current post
- 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
- Meta Query And/Or
- Use meta_query to get title of associated post
- Meta query with multiple custom fields for archives page ordering problem
- query posts custom field calculation value
- Get Data From wp_sitemeta for Multisite network
- Unique meta_key with array value vs repeated meta_key with single values
- get posts where a custom field contains a text
- How can I do a variable for meta_query?
- 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
- ORDER BY custom field value out of where clause
- comment meta_query for keys that aren’t yet set
- ACF: How to get users with a ACF flexible content subfield with a specific value AND layout?
- Sort custom post type by most current date picker
- change order of images attached to post
- Diamond question mark in text after migrating content
- Convert all dates stored in custom field
- query_posts with meta_value
- Custom search SQL Query to add custom field in result
- How to put forward a blog post
- Show single posts date, in a page of posts