Note: You are viewing the documentation for Version 3View Version 4 Docs

Documentation

View the installation guide, browse the Knowledge Base, find out about SearchWP's many hooks, get support

Available since: 1.0

searchwp_custom_field_keys

View Parameters »

When adding keyword weights to Custom Fields on the SearchWP settings screen, you may notice some Custom Field names missing. SearchWP only lists the 25-most used Custom Fields by default, but you can customize that list to add your own.

Note: after adding your own Custom Fields, you will need to return to the SearchWP settings screen and add your new Custom Field weight.

Example: If you want to add two Custom Fields to the SearchWP settings screen, add the following to your active theme’s functions.php:

<?php
function my_searchwp_custom_field_keys( $keys ) {
$keys[] = 'my_first_meta_key';
$keys[] = 'my_second_meta_key';
return $keys;
}
add_filter( 'searchwp_custom_field_keys', 'my_searchwp_custom_field_keys', 10, 1 );
view raw gistfile1.php hosted with ❤ by GitHub

Example: You can also perform LIKE matches to Custom Field names. This is especially useful when wanting to add fields from Advanced Custom Fields that are nested, Repeaters, or Flexible Content fields. To add LIKE matches to a set of Custom Field meta keys, add the following to your active theme’s functions.php:

<?php
function my_searchwp_custom_field_keys_like( $keys ) {
$keys[] = 'acf_field_name_%'; // will match any Custom Field starting with acf_field_name_
return $keys;
}
add_filter( 'searchwp_custom_field_keys', 'my_searchwp_custom_field_keys_like' );
view raw functions.php hosted with ❤ by GitHub

Parameters

Parameter Type Description
$keys Array

Meta keys for this post type

Fix keyword search on your site. No coding required!

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

Get SearchWP