As mentioned in the comments you an issue in your meta query, as you set the key to 20161126
or similar. Instead key
should be filled with your meta key post_end_date
. Meta query also support multiple arrays to combine your query to also include posts where the meta key is not set. The example would be something like the following:
function expiry_filter($query) {
if( !is_admin() && $query->is_main_query() ) {
$expire = get_field('post_end_date') ? : date('Ymd');
$query->set( 'meta_query', [
'relation' => 'OR',
[
'key' => 'post_end_date',
'value' => $expire,
'compare' => '>=',
'type' => 'NUMERIC',
],
[
'key' => 'post_end_date',
'compare' => 'NOT EXISTS',
],
]);
}
}
add_action( 'pre_get_posts', 'expiry_filter' );
Related Posts:
- Using meta_query and custom fields within pre_get_posts to return posts within a numerical range
- Comparing arrays with meta_query in pre_get_posts
- Multiple orderby date arguments
- Filtering multiple custom fields with WP REST API 2
- WP REST API: Order posts by meta value (acf)?
- Meta Query “IN” doesn’t work with ACF checkbox filter
- Query between dates using Date Picker fields
- Check for the existence of custom field
- ACF repeater field with meta_query
- sort by date in Advanced Custom Field
- Get specific repeater row (via advanced custom fields) based on Meta Query with Wildcards [closed]
- Query between dates using date picker filter breaks in WordPress 4.2.1
- WP_Query meta_query >= date
- Using pre_get_posts for meta value of LIKE comparison on ACF repeater sub field
- Advanced custom fields: Customise date picker’s start date (need to choose year 1500 onwards) [closed]
- Display post in order of ACF checkbox?
- Update post meta value as date difference between two fields
- How to break a date from ACF?
- WordPress Date with ACF
- Filter posts by advanced custom field
- Get posts with multiple meta values
- Get users based on month ACF datepicker field
- How can you query posts by advance custom field when the value is a serialized array? [closed]
- Using WP meta query to show custom post types by a start and finish date
- Query by radio button ACF
- pre_get_posts hook not targeting search results page query
- WP get_posts meta_query using ACF repeater field
- get_posts filter meta_query using ACF Checkbox
- Display posts every specific day
- Comparing two dates (ACF and current time)
- How to use germ_terms() with meta_query for ACF Taxonomy field?
- Convert number to date format within an array
- Pre get posts sort by meta key returns no results if meta key does not exist
- Array sorting by custom field date
- Display “Today” Instead of Date for Pubslished Posts
- Time sort with meta_key using UNIX timestamp failing due to date differences
- WP_Query filtering in ACF field containing dates
- Widget Code / Advanced Custom Fields / Elementor
- getting image from ACF
- Need to search a custom field (ingredients, one long string per post), but want it to allow phrases/non-exact matches
- TinyMCE’s “Clear Formatting” button doesn’t remove lists and headings
- Order WP_Query by meta_key priority when ‘OR’ relation used for multiple meta values
- How can I apply an ACF field to a single custom post if it refers to the taxomy of that post type in the rules?
- ACF: If field contain a specific value, update value in another field
- ACF: Update field value based on value of another field
- Getting “Years Only ” from ACF Date Picker field to Hidden filed in the fields group
- How to only show ACF field if another block is being used?
- Need to check if user has completed a woo commerce payment
- ACF Select Field can’t return Array
- ACF: Grid based on field value
- Equation input with preview in classic editor
- How to show related post having same relationship filed under single CPT?
- Prevent other hooks from firing after wp_update_post() outside of editor
- ACF: How to query for a given value count of an array like field? (e.g.: How many rows has a `flexible_content` field?)
- Can I use WP blocks in a template?
- Set post publish date by custom field
- Use Acf Repeater data as options for a different acf custom select field
- Where to place CSS if add a new layout to FLexible Content Template
- Trying to update repeater field (ACF) dynamically with data from Contact Forms 7
- Update field for repeater not working
- ACF get group fields from current post taxonomy
- How can i add service category here? [duplicate]
- Get title color from category custom field
- Advanced Custom Field Textarea not Showing (ListingPro Theme)
- Using the WP CLI to output the HTML results of calling a post?
- Image is displaying with the url of the image as well
- WP Cron Working, but Function Not Working
- meta_query Array
- Can’t get the frontend cache to be deleted manually
- Order resultset by configured value and then list all the rest
- How to get a product’s Custom Fields in a different template file?
- How to do a WP_Query when a post has a relationship to anoter post via an ACF Post Object field, where the related post is in a certain category?
- Explore custom posts (CPT UI & ACF) database from WP UI
- Custom ACF block only outputs commented JSON to the DOM
- search form for custom fields
- Tax query get first product with attribute value in pre_get_posts
- Woocommerce products search with custom fields
- Excluding posts from search results page with meta query not working
- wanted to sort the wp_query array by two ACF field (Year and month)
- ACF – get custom taxonomy term image field
- Populating ACF Image Fields from JSON file
- How to add a custom field for image in “Text and Full Image(text right)” layout?
- Custom Post Type and Structure Question
- ACF group field disappeared after deployment using deployer script
- Trying to add ACF to authors meta and adding a class at the same time
- Fill up advanced custom field of a custom post type via API REST POST
- Two problems that are likely related to AJAX
- Filter result of Custom Post Type using meta_query with ACF
- Fancybox3 ACF repeater. URL strip out from the caption field
- ACF – Eliminate unnecessary data and print
- Is it okay to use an ACF field to store a password for a protected area of a page?
- meta_query is overriding default search
- Is there any way to bulk search-replace URLs that exist within ACF’s “Link” field type (serialized)?
- Query Product categories what have a custom field
- Transitioning Laravel App into WordPress (Portfolio Website)
- ACF unable to use user field
- If Statement is Ignored?
- Get values from an advanced custom field
- Query posts by current ACF meta key value on single page as related posts
- get the title of a relationship field