Skip to content

Instantly share code, notes, and snippets.

@searchwpgists
Created March 29, 2022 13:34
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 searchwpgists/986bb256660dd25f5a584d61a634017d to your computer and use it in GitHub Desktop.
Save searchwpgists/986bb256660dd25f5a584d61a634017d 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