searchwp\source\attribute\options
Depuis : 4.0.0
Table des matières
Modifiez les options d'attribut pour une source.
Paramètres
| Type | Paramètre | Défaut | Depuis | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Tableau | $options |
Options d'attribut définies | 4.0.0 |
|||||||||||||||
| Tableau |
$args
|
4.0.0 |
||||||||||||||||
Exemples
Tous les hooks doivent être ajoutés à votre plugin personnalisé SearchWP Customizations Plugin.
Ajouter des options d'attribut de métadonnées 'extra'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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 ); |

