Skip to content

Instantly share code, notes, and snippets.

@propertyhive
Last active August 18, 2025 16:24
Show Gist options
  • Save propertyhive/dc8c9224726da2def3b90ccbac30543c to your computer and use it in GitHub Desktop.
Save propertyhive/dc8c9224726da2def3b90ccbac30543c to your computer and use it in GitHub Desktop.
add_action( "houzez_property_feed_pre_import_properties_xml", 'check_for_big_drop', 10, 2 );
function check_for_big_drop( $properties, $import_id )
{
// get number of existing published properties imported for this import
$args = array(
'post_type' => 'property',
'posts_per_page' => -1,
'post_status' => 'publish',
'fields' => 'ids',
'meta_query' => array(
array(
'key' => '_imported_ref_' . $import_id,
'compare' => 'EXISTS',
)
)
);
$property_query = new WP_Query($args);
$existing_properties = $property_query->found_posts;
$incoming_properties = count($properties);
// Check for a drop of more than 10%
if ($existing_properties > 0) {
$threshold = $existing_properties * 0.6; // 60% of current
if ($incoming_properties < $threshold) {
// ADDED THIS LINE:
wp_mail('[email protected]', 'Property import with ID ' . $import_id . ' halted', sprintf(
'Property import halted: existing = %d, incoming = %d (more than 40 percent drop detected).',
$existing_properties,
$incoming_properties
) );
wp_die(
sprintf(
'Property import halted: existing = %d, incoming = %d (more than 40 percent drop detected).',
$existing_properties,
$incoming_properties
),
'Import Aborted',
array('response' => 400)
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment