Skip to content

Instantly share code, notes, and snippets.

@searchwpgists
Last active March 29, 2022 13:04
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/415f0c4e85607716dd4ecd7aea5bcb72 to your computer and use it in GitHub Desktop.
Save searchwpgists/415f0c4e85607716dd4ecd7aea5bcb72 to your computer and use it in GitHub Desktop.
Add 'extra' metadata Attribute Options in SearchWP
<?php
// Add 'extra' metadata Attribute Options in SearchWP.
add_filter( 'searchwp\source\attribute\options', function( $options, $args ){
if( $args['attribute'] !== 'meta' ){
return $options;
}
$these_keys = [ 'my_custom_key' ];
foreach( $these_keys as $this_key ){
// Add this field if it's not added already.
if( ! in_array(
$this_key,
array_map( function( $option ){ return $option->get_value(); }, $options )
) ){
// Each option must be a \SearchWP\Option.
$options[] = new \SearchWP\Option( $this_key, 'Extra Metadata: ' . $this_key );
}
}
return $options;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment