Expired Listings not being Trashed
-
For anyone else that is seeing a bug where Listings aren’t being deleted/trashed in WordPress when they are expired on the IDX side, I wrote a little tool that shows you all of the expired listings in your Listings post type:
/** * Adding expired listings page */ function pp_idx_admin_page() { add_submenu_page( 'edit.php?post_type=listing', 'Expired Listings', 'Expired Listings', 'manage_options', 'expired_listings', 'pp_expired_listings_view' ); } add_action( 'admin_menu', 'pp_idx_admin_page' ); /** * Creates the view for the expired listings page */ function pp_expired_listings_view() { $nonce = isset( $_POST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ) : false; $expired_request = wp_verify_nonce( $nonce, 'mls-expired-nonce' ) ? $_POST : false; // Retrieve applicable query parameters. $mls_base_url = isset( $expired_request['mls_base_url'] ) ? sanitize_text_field( $expired_request['mls_base_url'] ) : null; if ( $mls_base_url ) { update_option( 'mls_base_url', $mls_base_url ); } else { $mls_base_url = get_option( 'mls_base_url' ); } ?> <div class="wrap"> <h1>Expired Listings</h1> <p>Warning: This does check for a 404 on the mls url so it might take a bit to run. Don't run this excessively.</p> <p>You can use the Edit button in the Result to Trash the listing.</p> <form method="post"> <label for="mls_base_url">MLS Base URL</label> <input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( 'mls-expired-nonce' ) ); ?>"> <input type="text" required name="mls_base_url" id="mls_base_url" value="<?php echo esc_url( $mls_base_url ); ?>" placeholder="https://mls.myagency.com" class="regular-text"> <input type="submit" name="submit" value="Check Expired Listings" class="button button-primary"> <?php if ( isset( $_POST['mls_base_url'] ) ) { $args = array( 'post_type' => 'listing', 'posts_per_page' => -1, ); $all_listings = get_posts( $args ); $mls_urls = array(); foreach ( $all_listings as $listing ) { $mls = get_post_meta( $listing->ID, '_listing_mls', true ); array_push( $mls_urls, array( 'url' => "$mls_base_url/idx/moreinfo/b232/$mls", 'type' => 'GET', ), ); } $requests = Requests::request_multiple( $mls_urls ); $has_expired = false; foreach ( $requests as $key => $request ) { if ( ! property_exists( $request, 'status_code' ) ) { continue; } if ( 404 === $request->status_code ) { $has_expired = true; $expired_listing = $all_listings[ $key ]; ?> <p> <a href="<?php the_permalink( $expired_listing->ID ); ?>"> <?php echo esc_html( $expired_listing->post_title ); ?> </a> | <a href="<?php echo esc_url( get_edit_post_link( $expired_listing->ID ) ); ?>"> Edit </a> | <a href="<?php echo esc_url( $mls_urls[ $key ]['url'] ); ?>"> MLS Page </a> </p> <?php } } if ( ! $has_expired ) { echo '<p>No expired listings found.</p>'; } } ?> </form> </div> <?php } ?>
You can either put this code in a new plugin or in your functions.php file. This is pretty rough, so use at your own risk, but wanted to share my workaround for others that ran into this issue.
- The topic ‘Expired Listings not being Trashed’ is closed to new replies.