I have done some more reseach and come accross the following article which does exactly what I want it to do. According to the writer, the code works but when I try and adapt it to my circumstance it doesn't update the post status. Could someone please tell me what I am doing wrong?

The original code:

$ap = get_post_meta($post->ID,'sub_seminars_0_start_date',true);
$startdate = date("Ymd", strtotime($ap));
$todaydate = date("Ymd");
if(strtotime($todaydate) > strtotime($startdate) && !empty($ap)){
    $del_data = array(
                'Ref' => 'sub_seminars_0_ref',
                'Start date' => 'sub_seminars_0_start_date',
                'End Date' => 'sub_seminars_0_end_date',
                'Venue' => 'sub_seminars_0_venue',
                'Fees' => 'sub_seminars_0_fees',
                'CPE Credits' => 'sub_seminars_0_cpe_credits'
delete_row('sub_seminars', 1);

This is my code in my functions.php file:

function expire_posts () {
    $post_id = get_the_ID();
    $getdate = get_post_meta($post_id, 'Expiry Date', true);
    $expirydate = date ( 'd F Y', strtotime ($getdate));
    $today = date( 'd F Y' );
    if ( strtotime($expirydate) < strtotime($today) ) {
        $postdata = ( array (
                'ID' => $post_id,
                'post_status' => 'expired',
                'post_modified' => $today,
        wp_update_post ($postdata);
  • "doesn't work" is not an actual question. "Remote debugging" is not easy to do, and if the issue was obvious you would have probably saw it yourself..... you should edit the question, and include what is it that you expect to happen, what actually happened, and any debugging information you collected. – Mark Kaplun Mar 14 '18 at 11:51
  • Hi Mark I have updated my question. Unfortunately I have no debugging info. I have activated debugging mode as well as the debug.log but it hasn't come up with anything. – Ragnaboy Mar 14 '18 at 12:06

You seem to confuse WP_Meta_Query with WP_Query obviously they are not the same and you can not use the first by itself to loop over post.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.