Large Number of Auto-Generated Regions Causing Issues

Hi,

After creating 1250 listings I noticed that profile image update is leading to WP’s critical error warning. Then I found the geolocation plugin is creating the issue. Initially, under HivePress → Settings → Regions, I enabled “Generate regions from locations” with multiple location levels, including Country, Region, Sub-region, City.

This resulted in HivePress generating a very large number of region taxonomy terms from the listing locations. I found the reason was similar to the issue explained in this post Out of memory issue with regions enabled - General / Geolocation - HivePress Community.

I now want to keep only Country selected. So that the max regions will reduce to 100+. Will this help in resolving the above issue? In that case, what is the recommended way to remove the previously generated Region/Sub-region/City terms while preserving the existing listings and their location/address data? Will deleting these terms affect listing locations, coordinates, maps, or search functionality?

Also, could having several thousand generated Region terms affect performance when editing listings/profiles or uploading images?

What is the recommended PHP Memory Limit for 5000 listings that and later it will increase to 8000. Number of attributes created are 10 and under these approx 40-50 options are there.

Waiting for your valuable suggestion.

Thanks & regards,

Krishnakumar

Hi,

Thanks for reporting the issue, we already prepared API to resolve this in the core plugin and updated it, and this would be finally resolved in the upcoming Geolocation update. As a temporary fix, you can restrict the regions to countries/states, and use the below code snippet to cleanup the previously generated regions:

add_action(
	'template_redirect',
	function() {
		if ( ! isset( $_GET['cleanup_regions'] ) ) {
			return;
		}

		$listing_ids = get_posts(
			[
				'post_type'      => 'hp_listing',
				'post_status'    => 'any',
				'posts_per_page' => 200,
				'fields'         => 'ids',
				'orderby'        => 'rand',
				'tax_query'      => [ [ 'taxonomy' => 'hp_listing_region', 'operator' => 'EXISTS' ] ],
			]
		);

		foreach ( $listing_ids as $listing_id ) {
			wp_set_object_terms( $listing_id, [], 'hp_listing_region' );
		}

		if ( $listing_ids ) {
			wp_die( 'Cleared ' . count( $listing_ids ) . ' listings, reload to continue.' );
		}

		$region_ids = get_terms( [ 'taxonomy' => 'hp_listing_region', 'fields' => 'ids', 'hide_empty' => false ] );

		foreach ( $region_ids as $region_id ) {
			wp_delete_term( $region_id, 'hp_listing_region' );
		}

		wp_die( 'Done. Deleted ' . count( $region_ids ) . ' regions.' );
	}
);

Once you add it, append “/?cleanup_regions=1” to your website URL and refresh the page untill the “done…” message is displayed, then you can remove the code snippet.

Regarding the memory limit, it depends on many factors and I suggest testing this per website. In any case, I recommend choosing a VPS hosting (or DigitalOcean if you’re familiar with basic server setup), it makes scaling (if needed) easier and cheaper. We’ll also try to optimize HivePress with every update, for example we plan to add the “lookup tables” feature to significally speed up the listing search.

Hope this helps