diff --git a/docs/customization/yoast-seo/filters/custom-fields-pre-query-filter.md b/docs/customization/yoast-seo/filters/custom-fields-pre-query-filter.md new file mode 100644 index 00000000..4f1e3724 --- /dev/null +++ b/docs/customization/yoast-seo/filters/custom-fields-pre-query-filter.md @@ -0,0 +1,73 @@ +--- +id: custom-fields-pre-query-filter +title: "Yoast SEO: Short-circuit the custom fields lookup" +sidebar_label: Short-circuit custom fields lookup +--- + +The `wpseo_custom_fields_pre_query` filter lets you bypass Yoast SEO's default +`SELECT DISTINCT meta_key` query against the `wp_postmeta` table. On sites with +a very large `postmeta` table, that query can be slow. Use this filter to supply +a pre-computed or alternative list of custom field keys, and Yoast SEO will skip +the database query entirely. + +## Parameters + +| Parameter | Type | Description | +|------------------|-------------------|---------------------------------------------------------------------------------------------| +| `$custom_fields` | `string[]`\|`null`| Pre-computed list of `meta_key` names. Return `null` to let the default query run. | +| `$limit` | `int` | The configured result limit (default `30` via `postmeta_form_limit`). Honor it in custom queries. | + +When the filter returns a non-null array, Yoast SEO uses that array directly and +does **not** run the default query. + +## Usage + +### Supplying a static list + +```php +