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

searchwp\source\attribute\options

Since: 4.0.0

Table of Contents

Modify the Attribute Options for a Source.

Parameters

Type Parameter Default Since
Array $options Defined Attribute Options 4.0.0
Array $args
Key Type Value
source String Source name
attribute Stri Attribute name
search String Search string (if searching)
include Array Subset of Options to limit to
4.0.0

Examples

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

Add 'extra' metadata Attribute Options

<?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
);

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