Search Advanced Custom Fields Data in WordPress

Advanced Custom Fields Logo

Everybody loves ACF (Advanced Custom Fields)!

With over 1 million active installs, not only is it arguably the most popular custom field plugin for WordPress, it’s one of the most popular WordPress plugins ever made. That’s not without good reason:

  • The user interface is great
  • The updates are constant
  • The community is huge (and helpful)

Working with Custom Fields has become an essential part of establishing WordPress as a CMS as opposed to a simple blogging platform, and ACF has spearheaded that effort by lowering the barrier to entry for millions of websites.

WordPress does not search Custom Fields!

While ACF does a fantastic job of utilizing WordPress’ Custom Fields (post meta) for structured data storage, WordPress does not search any of that content!

Many websites built by WordPress that use ACF put the vast majority of content in Custom Fields (and not the main editor) and for good reason, it provides a much nicer interface to work with and reduce error.

Unfortunately a byproduct of this means that hardly any of your site content is considered when performing searches. That’s a huge problem!

SearchWP ? ACF

SearchWP was built on the knowledge that this problem plagues many WordPress sites that use Advanced Custom Fields.

Sure, there are ways to JOIN WordPress post metadata with the main search query, but performance instantly suffers. The problem grows exponentially as you make more liberal use of ACF (which we all do!)

SearchWP abstracts ACF’s data while building its index, creating an optimized search environment that not only includes all of your Custom Field data in searches, you can also weight individual ACF fields!

Easily add individual Advanced Custom Fields to your engine configuration!

ACF Repeaters and Sub-fields: no problem!

Advanced Custom Fields success is based on its many versatile field types. Some field types have a data structure that can sometimes be challenging to work with when attempting to manually JOIN in a native WordPress search. SearchWP allows you to define custom meta keys with wildcards. This makes it super easy to accommodate an entire Repeater group for instance:

Easily group ACF Repeater fields in SearchWP

Adding these custom meta keys is as easy as adding the following to your theme’s functions.php and then adding the Custom Field to your SearchWP engine:

function my_searchwp_acf_repeater_keys( $keys ) {
$keys[] = 'staff_%'; // will match all ACF Repeater fields in the Staff repeater
return $keys;
add_filter( 'searchwp_custom_field_keys', 'my_searchwp_acf_repeater_keys' );
view raw functions.php hosted with ❤ by GitHub

SearchWP supports pre-processing data

One of Advanced Custom Fields popular fields is a Relationship field. This field type stores an array of post IDs that aren’t very useful when it comes to searching. Usually when a Relationship field is used you instead want to search the actual content of the chosen entries stored in the field.

This is easily done with SearchWP because you can integrate custom processing into SearchWP’s indexing process! In this example we can perform some additional processing of the Relationship field content by utilizing SearchWP’s searchwp_custom_field_{name} hook.

Let’s say we have a Relationship field and instead of indexing the post ID as stored by ACF we instead want to have SearchWP index the post Title. We can do that easily by adding the following to our theme’s functions.php and rebuilding our index:

function my_searchwp_acf_relationship_processor( $existing_value, $the_post ) {
if ( ! is_array( $existing_value ) ) {
return $existing_value;
// We want to index Titles not IDs
$content_to_index = '';
// Iterate over stored ACF Relationship field and retrieve Title for each item
foreach ( $existing_value as $related_post_data ) {
if ( is_numeric( $related_post_data ) ) {
$post_title = get_the_title( absint( $related_post_data ) );
$content_to_index .= $title . ' ';
} else {
$related_post_data = maybe_unserialize( $related_post_data );
if ( is_array( $related_post_data ) && ! empty( $related_post_data ) ) {
foreach ( $related_post_data as $related_post_id ) {
$post_title = get_the_title( absint( $related_post_data ) );
$content_to_index .= $title . ' ';
// Instead of indexing the original ACF field value (likely array of IDs)
// we will instead be indexing a string of Titles for each chosen post
return $content_to_index;
// Adds additional processing for ACF field with the name my_acf_relationship_field
add_filter( 'searchwp_custom_field_my_acf_relationship_field', 'my_searchwp_acf_relationship_processor', 10, 2 );
view raw functions.php hosted with ❤ by GitHub

The sky’s the limit!

SearchWP was built because Advanced Custom Fields changed the game when it comes to WordPress. The content stored therein is structured in a way that can be replicated in SearchWP, allowing you to fine-tune your search configuration to match your ACF setup!

Fix Search on Your Site. No Coding Required!

Now you can utilize all of the content that's gone unrecognized by native WordPress search instantly with SearchWP

Get SearchWP