ACF saves the value as Ymd
format in database regardless of display and return format. All you need is a meta query to fetch the correct posts.
function expire_posts_function() {
//Get Expired Posts only
$expired_posts = get_posts(arrasy(
'post_type' => 'event',
'posts_per_page' => -1,
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'ev_date',
'value' => date('Ymd'),
'compare' => '<',
),
),
));
//Loop through the posts and set status
if ( $expired_posts ) {
foreach( $expired_posts as $expired_post ) {
wp_insert_post(array(
'ID' => $expired_post->ID,
'post_status' => 'draft',
));
}
}
}
Related Posts:
- importing third party json feed as custom post type [closed]
- how to get posts by custom post type then display Custom fields?
- WP Rest API Querying Custom Posts by ACF fields
- How to sort a table of custom posts by column containing custom field
- Meta Query “IN” doesn’t work with ACF checkbox filter
- Insert slider (Custom Post Type) into pages
- get terms that have post with custom post type between 2 values
- How to set custom post type as post title to avoid ‘Auto Draft’
- Archive filter disappears on no results?
- Query current and future events, ordered by begin date
- Change message given when deleting post from custom post type
- Building an Advanced Search (text, tags, category, custom fields) – Getting the wrong SQL query
- Linking three taxonomies with ACF
- Query Custom Post Types by date (custom field) range
- Link users to a custom post type
- Remove duplicated values from a loop
- How to retrieve category NAME instead of ID in a function with a taxonomy custom field?
- “add_post_type_support” with Custom Post Type & ACF
- Custom Post type and Custom Field WP_Query
- Display multiple custom post types and sort them chronological by one of their fields
- Validate custom fields before save using WordPress Rest API
- get_posts of Custom Post Type AND Custom Taxonomy
- How can I dynamically add a post to a custom post type which uses a custom field?
- the_content() not outputting anything (Advanced Custom Fields)
- How to add a post slug to a url?
- ACF Field on CPT Slug
- Custom Post Type + ACF and performance [closed]
- Meta Query Not Returning Output Despite Having Matching Values
- ACF From & To Date Validations
- Retrieve custom field from Contact Form 7 [closed]
- The loop seems stuck to a single (now deleted) post
- How to update post meta on uploaded image from a custom form?
- Multiple Frontend Filters Using Advanced Custom Fields
- Order post by date with ACF
- Displaying custom field according to date
- How to set the seo title tag on a page by page basis?
- How to add/edit advanced custom fields on custom post type’s WordPress REST API?
- Sort a custom post with ACF: Date Picker & Display Featured!
- Post loop count is not in order
- How to inherit field value from parent post into in child / sub post
- Custom Post Type page sorts differently on different environments
- Postname on unique permalink structure appends “-2” for a custom post type. How can I get this to stop happening?
- Custome fields not displayed
- Create short URL with auto 301 redirect
- Why is wp api returning old acf values?
- How to use single.php for creating, reading and editing Custom Posts with ACF
- get custom post type value in header.php [closed]
- How do I get_the_postID() for a custom post that uses ACF repeater field?
- Custom fields not showing in custom post type
- Group by custom field value (start and end times)
- Custom post types, disable fields
- wp-includes does not contain a feed template
- Using WP meta query to show custom post types by a start and finish date
- Advanced custom field – posted fields from custom post type
- Excerpt length: get first paragraph
- How to display author details in a custom post type in the wordpress backend?
- Show/hide posts and categories based on user meta
- Fetch data from two custom post types and create multidimensional array for output to html table
- Having a repeating custom field in admin custom post type, what I’d go better with, for DB’s sake? ACF repeater or query a different post type?
- Set up a WP Cron scheduled event to update calculated ACF field
- Query filter by value in meta_value array
- count & sum the value of custom field of the author post in dynamic posts
- Orderby custom fields is not working
- Custom post ID & display information related to this ID
- Show custom post type event if current day using ACF
- WP_Query not using custom taxonomy categories on custom post type
- How would i insert a value of custom field from Advaced Custom Field into shortcode generated by Gravity Forms [closed]
- Issue to display Permalink (ACF Relationships in Custom Post Type )
- Auto generate excerpt from ACF field on a CPT that does not support excerpt or content
- Custom post type not pulling CSS
- Button link display in shortcodes using custom field in ACF
- How do I link to a dynamic ACF button from a Custom Post type?
- Changing default admin column sorting to an ACF Date Picker field
- Taxonomy shows up twice on Custom Post Type
- How to hide sub fields in a field group and also the entire field group if the answer selected is “no”
- Create 3 Levels of relations with WordPress
- Linking posts together with Advanced Custom Fields “both ways”
- save_post affect creation and deletion
- How can I save a Custom Post Title and Slug with a Custom Field?
- Custom permalink rewrite rules – how do I fix this?
- Custom Field as Custom Post type element class
- Extracting Post ID and passing through as an attribute in a shortcode
- Automatically convert standard posts with custom fields to custom post types
- Submit and edit font end custom post type
- How to make a custom search template for custom taxonomy?
- Making my custom column sortable
- Get month and day from a Date Picker custom field
- How to query posts by meta keys AND under specific category?
- how to load custom single.php?
- Setting a custom $query->query_vars[‘meta_key’] breaks the WordPress menu
- Function that get ACF fields value before saving
- Modifying and Displaying URL’s in a Post Template using parse_url
- Custom post type adding additional markup
- Advanced Custom Fields: query posts filtered by multiple field values
- Register a title automatically with a relationship field
- WooCommerce – Complete Order when an action occurs
- WordPress Loop trouble with ACF [closed]
- Is it possible to specify a time interval (from, to) in ACF with date picker, or other custom field?
- Why custom search engine only searches in post titles of custom posts?
- Display ACF object field data using Elementor Custom Query