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

searchwp\source\post\attributes\meta

Since: 4.0.0

Table of Contents

Manipulate Custom Field (postmeta) data before it is indexed.

See also searchwp\source\post\attributes\meta\${meta_key} for a single Custom Field.

Parameters

Type Parameter Default Since
Mixed $meta_value Custom Field value (after it has been run through searchwp\source\post\attributes\meta\${meta_key}) 4.0.0
Array $args
Key Type Value
post_id Integer Post ID
meta_key String Custom Field key
meta_value Mixed Custom Field value
4.0.0

Examples

All hooks should be added to your custom SearchWP Customizations Plugin.

Add additional content to Custom Field

<?php
// Add additional content to Custom Field during indexing in SearchWP.
add_filter( 'searchwp\source\post\attributes\meta', function( $meta_value, $args ) {
if ( 'my_custom_field_key' !== $args['meta_key'] ) {
return $meta_value;
}
// Add 'coffee' to Custom Field value to make it searchable.
return $meta_value . ' coffee';
}, 20, 2 );

How to use this code

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