Skip to content

Fellows meta query scales poorly on continent-level region pages #533

@FredericoAndrade

Description

@FredericoAndrade

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions