Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

WordPress’s built-in keyword search does not search custom-field text by default. Use WP_Query with meta_query when you need to filter posts by a known field and value; use a search plugin configured to index selected custom fields when ordinary search terms should match text stored in those fields. A custom index or integration is appropriate for unusual storage, ranking, or data-source requirements.

First decide what “searchable” means

There are two different tasks that are often described as custom-field search:

  • Structured filtering: find records where a field equals a value, exists, falls within a range, or matches a limited pattern.
  • Free-text search: let visitors type normal keywords and match text stored in one or more custom fields, ideally with relevance ranking and highlighting.

These use different mechanisms. A metadata query filters database records; it does not add every custom field to WordPress’s general keyword index.

Choose the right implementation

Requirement Recommended approach Important trade-offs
Field equals a known value WP_Query with meta_query Choose the exact field key, comparison operator and data type. This is filtering, not general keyword search.
Field exists, is empty, or matches a constrained pattern meta_query Useful for known conditions, but database filtering is not relevance-ranked full-text indexing.
Visitors’ normal search words should match selected field text Configure a search plugin such as Relevanssi to index chosen fields Select fields deliberately, confirm storage compatibility, and rebuild or update the index when the plugin requires it.
Custom ranking, external data, or non-standard storage Custom integration or plugin hooks Requires development, testing and continuing maintenance for every storage location and update path.

Filter posts by a custom-field value with meta_query

Use a metadata query when your application already knows which field and condition to test. The key is the stored custom-field name, while value, compare and (when needed) type define the condition.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<?php
$query = new WP_Query([
    'post_type'  => 'product',
    'meta_query' => [
        [
            'key'     => 'material',
            'value'   => 'cotton',
            'compare' => '=',
        ],
    ],
]);
?>

This returns products whose material metadata equals cotton. For numeric ranges, specify a numeric type so comparisons are not treated as plain text:

'meta_query' => [
    [
        'key'     => 'rating',
        'value'   => [4, 5],
        'compare' => 'BETWEEN',
        'type'    => 'NUMERIC',
    ],
],

Common comparisons

  • = for equality.
  • EXISTS to require that a metadata key is present.
  • LIKE for a constrained substring condition.
  • BETWEEN, > or < for ranges, with an appropriate type such as NUMERIC or DATE.

Multiple clauses can be combined with a relation such as AND or OR. Verify the actual value format before choosing an operator: dates, numbers, booleans, serialized arrays and repeater-style data do not all behave like ordinary text.

Make custom-field text part of normal WordPress search

If the requirement is “a visitor searches for words and results can match text in these fields,” configure a search engine that indexes custom fields. Relevanssi documents options to index all custom fields, visible fields, or specifically named fields, and supports data stored in ACF and other custom-field systems.

Select fields instead of indexing everything

Index only fields that contain meaningful user-facing content. Indexing every field can pull in irrelevant metadata created by themes and plugins, which may produce noisy results and weaker relevance. A named allow-list is usually easier to audit than an all-fields setting.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check how the values are stored

Test ordinary text fields as well as empty values, repeated fields, serialized values and fields populated by imports or scheduled jobs. Plugin support and search behavior depend on the storage format. Fields saved in site-wide options rather than on individual posts may need additional integration because a normal post index is associated with post metadata.

Rebuild and verify the index

  1. Enable custom-field indexing in the search plugin’s settings.
  2. Choose the exact field names that should contribute to results.
  3. Run the plugin’s indexing or rebuild process if required.
  4. Search for distinctive words present only in each selected field.
  5. Test empty, missing and repeated values, then repeat the index update after changing field data.

Do not assume that changing a field immediately changes search results; the plugin’s indexing schedule and update hooks determine when the new value becomes searchable.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

ACF-specific considerations

Advanced Custom Fields stores values as post metadata, so the same distinction applies: use meta_query for a known field condition and a compatible search plugin for free-text indexing. Confirm the field’s stored name and value representation rather than relying only on the label shown in the editor.

ACF option-page values are site options, not metadata attached to an individual post. Searching those values generally requires extra integration or a custom indexing strategy that decides which post, result record or external document should represent the option data.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When custom code is the better choice

Build a custom integration when you need a ranking formula that a plugin cannot express, data from external tables or APIs, field values stored outside post metadata, or a specialized index updated by your own application events. Plan for schema changes, bulk reindexing, deletion handling, permissions and performance monitoring. This path offers control but creates an ongoing maintenance obligation.

Testing checklist

  • Confirm whether the requirement is filtering or free-text search.
  • Use the exact saved field key, not only its human-readable label.
  • Check the value’s type and storage format before selecting comparisons.
  • Include posts with missing, empty and repeated values in test data.
  • Verify that selected fields, and no unwanted plugin or theme metadata, are indexed.
  • Rebuild or refresh the index after configuration and bulk data changes.
  • Test option-page or other non-post data separately from post metadata.

The Bottom Line

Use meta_query for precise custom-field filters. Use a search plugin configured with a deliberate field list when custom-field text must match ordinary keyword searches; choose custom integration only when your data or ranking needs go beyond those approaches.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.