Bulk Remove Expiration Dates from All Listings

If you care about website performance and easier administration, I recommend using a code snippet plugin like WPCodeBox (or similar) for adding code to your website.

Instructions

  1. Create a new PHP code snippet.
  2. Copy the contents of code snippet below.
  3. Paste the contents into your code snippet.
  4. Review any notes that I’ve provided.
  5. Save and enable the code snippet.
  6. Test.

Snippet

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.

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 );
🔥NEW!🔥
Property Starter Site
MyListing Add-on
Launch Sale Ends: June 24th.

Club Guarantee

If you notice an issue with this product, I’ll fix it for free and get you an updated version.

Club Guarantee

If you notice an issue with a Club Product and the problem exists on the corresponding Starter Site, I’ll fix it for free.