Description
On continent-level region pages (e.g. /territories/asia), taxonomy-region.php builds a fellows gallery by constructing an OR meta_query with one LIKE clause per territory ID in the continent.
Asia has 215 territories, generating a query like:
WHERE (fellow_territory LIKE '%"1234"%' OR fellow_territory LIKE '%"5678"%' OR ... × 215)
This does not currently cause issues — both local and production run with memory_limit = -1. However, the query is O(n) in territory count and would exhaust a 128 MB memory limit on a more restrictive host.
Root cause
fellow_territory is a serialized ACF relationship field stored as a JSON-encoded array in a single wp_postmeta row. The only way to search it with the standard WP_Query meta API is LIKE, which forces one clause per territory.
Fix
Replace the per-territory LIKE loop with a single $wpdb raw query using REGEXP or a JOIN that finds all fellows whose fellow_territory meta value contains any of the territory IDs in one pass — O(1) queries regardless of territory count.
Location
wp-content/themes/blankslate-child/taxonomy-region.php lines 59–74
Status
Not actively failing. Deprioritized 2026-03-06 after confirming memory_limit = -1 on both local and production. Revisit if hosting constraints change.
Description
On continent-level region pages (e.g.
/territories/asia),taxonomy-region.phpbuilds a fellows gallery by constructing an ORmeta_querywith one LIKE clause per territory ID in the continent.Asia has 215 territories, generating a query like:
This does not currently cause issues — both local and production run with
memory_limit = -1. However, the query is O(n) in territory count and would exhaust a 128 MB memory limit on a more restrictive host.Root cause
fellow_territoryis a serialized ACF relationship field stored as a JSON-encoded array in a singlewp_postmetarow. The only way to search it with the standardWP_Querymeta API isLIKE, which forces one clause per territory.Fix
Replace the per-territory LIKE loop with a single
$wpdbraw query usingREGEXPor aJOINthat finds all fellows whosefellow_territorymeta value contains any of the territory IDs in one pass — O(1) queries regardless of territory count.Location
wp-content/themes/blankslate-child/taxonomy-region.phplines 59–74Status
Not actively failing. Deprioritized 2026-03-06 after confirming
memory_limit = -1on both local and production. Revisit if hosting constraints change.