Home Forums ACF PRO Expire Posts Reply To: Expire Posts

  • I do not completely understand your code.

    But this is setting the publish date to the current date

    $published_date = date('m/d/Y');

    also, because you are using ‘m/d/y’ which could give false results.

    You also need to include the statement global $post in your function if you are going to use $query->the_post();

    function listing_expiry_date() {
      global $post; // important
      // your query and loop
      // date calc
      $published_date = get_the_date('Y-m-d');
      $expire = date('Y-m-d', strtotime($published_date.' +3 days'));
      $today = date('Y-m-d');
      if ($today >= $expire) {
        // expire post