Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Last active April 1, 2020 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchristopher/b303af4acd16b3397b005ca8e5c9fed0 to your computer and use it in GitHub Desktop.
Save jchristopher/b303af4acd16b3397b005ca8e5c9fed0 to your computer and use it in GitHub Desktop.
Add 'extra' metadata to a SearchWP Entry
<?php
// Customize a SearchWP Entry before it is indexed.
add_filter( 'searchwp\entry\data', function( $data, $entry ) {
// Use this key when adding a Custom Field Attribute.
$extra_meta_key = 'my_extra_meta';
$value = 'This is extra data to index as extra meta';
// SearchWP's Post Meta Attribute expects that data is made of Tokens.
$data['meta'][ $extra_meta_key ] = new \SearchWP\Tokens( $value );
return $data;
}, 20, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment