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:
- Filter by custom field in custom post type on admin page
- Media library – Limit images to custom post type
- Filtering a WP_Query meta_query by numeric values isn’t working
- Populate a ACF Select Dropdown from Custom Post Type
- Filter a custom field based on selection of another custom field (ACF) [closed]
- ACF Relationships in Custom Post Type Permalink
- WordPress Search documentation: how to improve search query using taxonomy terms, custom meta fields?
- Retrieve a specific field from taxonomy term through advanced custom fields [closed]
- Count custom post types with a specific meta value
- Query by 2 values of a repeater ACF field
- Display posts if a custom field value is equal to another custom field value
- ACF Upload Image in repeater from front-end with custom form? – add_post_meta()
- Get Custom Field Values by Another Custom Field in WordPress
- ACF simple text field value not showing
- Post Object Filter by Custom Field, not title (ACF)
- Custom Post Types not showing, custom WP_Query
- Rewrite WordPress URL to show CPT meta field data
- Create 3 Level Relations with ACF and WordPress
- Multiple ACF Repeaters within a Custom Post Type
- How to change post featured image using a custom field of category?
- How to: Display ACF [fields] on Custom Post Types Utilising WordPress ‘Hooks’? [closed]
- Custom fields vs. Custom post types for a Portfolio Website
- Retrieve value of a category’s custom field
- Add custom ID to CPT posts only create not update
- WP_Query order by custom field, then randomly order some of results
- Cluster CPT posts to users based on ACF value from their profile on dashboard
- ACF Values Don’t Show After Import Unless I Edit/Update Post
- Stuck in Order by more then one
- How to render a custom post type template with custom fields using shortcode
- Query Custom Post Type Taxonomy term with multiple parameters
- Custom fields (wp_post_meta) vs Custom Table for large amount of data
- How to query WordPress posts bycustom field with a max characters’ length
- How to group posts and get a mixed posts and groups view?
- Custom Post Types vs. Advanced Custom Fields (with Repeater Field add-on)
- Integrate Custom Post Type Events into Calendar
- Displaying custom field according to date
- Advanced custom field boolean value in custom post type
- Why would social icon badges disappear after adding a custom post type?
- Sort a custom post with ACF: Date Picker & Display Featured!
- ACF repeater field usage
- 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
- Batch Extract Date from post title and put into ACF custom field
- Why is wp api returning old acf values?
- 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 post types, disable fields
- ACF Relationship Posts how to show additional content
- wp-includes does not contain a feed template
- Excerpt length: get first paragraph
- How can i show ACF in post excerpts
- count & sum the value of custom field of the author post in dynamic posts
- Grouping custom wordpress post types by acf value
- Set Post Private if no linked Post Objects (ACF)
- Show in an entry a Custom Post Type associated to a post
- Orderby custom fields is not working
- Display a Custom Post Type with Advanced Custom Fields on Homepage
- Filter result of Custom Post Type using meta_query with ACF
- Same custom post type with different ACF
- Custom sorting in post columns by ACF Pro Select Field
- 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]
- Auto generate excerpt from ACF field on a CPT that does not support excerpt or content
- Subpages URLs for Custom Post Type
- 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?
- How to show link to product in custom fields?
- How to hide sub fields in a field group and also the entire field group if the answer selected is “no”
- In the admin, how can you list thumbnails instead of titles for a custom post type?
- Looping through image object using ACF and CPT UI [SOLVED]
- WordPress page not showing up – replaced with last 10 posts?
- 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
- Best way to have one product in both rental and sale parent category
- How do I display specific custom posts, and how do I edit a post’s singular page?
- Automatically convert standard posts with custom fields to custom post types
- Showing custom post user wise with different color in wordpress
- Submit and edit font end custom post type
- How to make a custom search template for custom taxonomy?
- Making my custom column sortable
- Filter Content on all Post Types
- Get month and day from a Date Picker custom field
- Advanced Custom Fields – Add Field to Specific Page [closed]
- Modifying and Displaying URL’s in a Post Template using parse_url
- WooCommerce – Complete Order when an action occurs
- WordPress Loop trouble with ACF [closed]
- Elementor Custom Query to get Posts by ACF (Post Object Field
- Create WP multisites as a custom post type
- WordPress WP_Query Sort by 2 dates – custom fields
- Two custom post type relations
- selecting custom post types and taxonomies for hub page listing blocks
- Made a Custom Post Type using ACF. Via the dashboard I cannot see the view button to see the post
- Creating a Single Instance Custom Post Type with Limited Module Options using ACF and WPGraphQL
- How can I filter records in a custom post type list in the admin based on the ACF field in the post that contains the current user?
- WordPress duplicating posts from single loop
- How to automatically update ACF field value every year?
- Generate list of posts on a page, but fill shortcode values from ACF fields on that page