I have a date field that I am trying to access via PHP code. I need to know what format Types saves its date fields in to do this. The code is designed to delete posts once the date field value has been reached:
add_action( 'wp', 'expire_events_daily' );
function expire_events_daily() {
if ( ! wp_next_scheduled( 'delete_expired_events' ) ) {
wp_schedule_event( time(), 'hourly', 'delete_expired_events');
}
}
add_action( 'delete_expired_events', 'delete_expired_events_callback' );
function delete_expired_events_callback()
{
$args = [
'post_type' => 'job',
'posts_per_page' => -1,
'fields' => 'ids', //only get post id's
'meta_query' => [
[
'key' => 'job-closing-date',
'value' => current_time( 'Y/m/d' ),
'compare' => '<'
]
]
];
$events = get_posts( $args );
if ( $events ) {
// Loop through the post ID's and delete the post
foreach ( $events as $id )
wp_delete_post( $id );
}
}
As you can see I am using
'value' => current_time( 'Y/m/d' ),
And need to know if this is the way that Types saves dates.
Regards,
David