Join

Bulk Edit or Remove Listing Expiration Dates

Don't want to mess with guides or code snippets? This is a feature of MyListing Pro.

Let’s say you previously set an expiration date for your listings, but you want to adjust or remove the date without visiting each listing individually.

Bulk Edit Listing Expiration Dates

  1. Create a full backup of your website.
  2. Add the code snippet below to your website.
PHP
add_action( 'init', function() {
     if ( empty( $_GET['update_bulk_listing_expiry'] ) || ! current_user_can( 'administrator' ) ) {
        return false;
    }
     // Set your new listing expiry to a custom date
    $new_listing_expiry = date('Y-m-d H:i:s', strtotime('2025-12-31'));
     $next_data = 100;
    $offset = 0;
     do {
         $listings = (array) get_posts([
            'post_type' => 'job_listing',
            'offset'   => $offset,
            'posts_per_page' => $next_data,
            'post_status' => ['publish', 'draft', 'expired', 'pending']
        ]);
         printf(
            "Fetching listing expiry data from listing %d to %d <br />",
            $offset + 1,
            $offset + $next_data
        );
         flush();
        ob_flush();
         foreach ( $listings as $listing ) {
            // Update new listing expire
            update_post_meta( $listing->ID, '_job_expires', $new_listing_expiry );
            $updated = wp_update_post( [ 'ID' => $listing->ID, 'post_status' => $listing->post_status ] );
        }
         $offset = ( ! $offset ) ? $next_data : $offset + $next_data;
     } while( ! empty( $listings ) );
     exit('All listings are updated, you may close this window');
} );
  1. Adjust line 6, replacing ‘2025-12-31’ with your desired expiration date.

Note: You may need to adjust line 7 to match the number of listings on your website. Otherwise, the code snippet will not check more than 100 listings.

  1. Visit the following URL on your website, replacing domain.com with your domain.
https://domain.com/?update_bulk_listing_expiry=1
  1. Hit ENTER to execute the code snippet and wait for the script to finish running against your listings.
  2. Remove the code snippet from your website.

Bulk Remove Listing Expiration Dates

  1. Create a full backup of your website.
  2. Add the code snippet below to your website.
PHP
add_action( 'init', function() {
    if ( ! isset( $_GET['update_listing_expiry'] ) || ! current_user_can( 'administrator' ) ) {
        return;
    }
         $next_data = 100;
    $offset = 0;
         do {
        $listings = (array) get_posts( [
            'post_type' => 'job_listing',
            'offset'   => $offset,
            'posts_per_page' => $next_data,
            'post_status' => 'any'
        ] );
         printf(
            "Fetching listings from listing %d to %d <br />",
            $offset + 1,
            $offset + $next_data
        );
         flush();
        ob_flush();
         foreach ( $listings as $listing ) {
            update_post_meta( $listing->ID, '_job_expires', '' );
            $updated = wp_update_post( [ 'ID' => $listing->ID, 'post_status' => 'publish' ] );
        }
     } while( ! empty( $listings ) );
    exit('All listings are updated, you can close this window.');
}, 250 );
add_action( 'mylisting/admin/save-listing-data', function( $post_id, $listing ) {
     // update expiry date
    if ( isset( $_POST['mylisting_modify_expiry'] ) && $_POST['mylisting_modify_expiry'] === 'yes' ) {
        $expiry_date = ! empty( $_POST['mylisting_expiry_date'] ) ? strtotime( $_POST['mylisting_expiry_date'] ) : false;
        if ( $expiry_date ) {
            update_post_meta( $post_id, '_job_expires', date( 'Y-m-d', $expiry_date ) );
        } else {
            delete_post_meta( $post_id, '_job_expires' );
        }
    }
}, 99, 2 );

Note: You may need to adjust line 5 to match the number of listings on your website. Otherwise, the code snippet will not check more than 100 listings.

  1. Visit the following URL on your website, replacing domain.com with your domain.
https://domain.com/?update_bulk_listing_expiry=1
  1. Hit ENTER to execute the code snippet and wait for the script to finish running against your listings.
  2. Remove the code snippet from your website.