SearchWP Documentation

Consultez le guide d’installation, parcourez la base de connaissances, découvrez les nombreux hooks de SearchWP

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
Clé Type Valeur
source Chaîne Nom de la source
attribut Chaîne Nom de l'attribut
recherche Chaîne Chaîne de recherche (en cas de recherche)
inclure Tableau Sous-ensemble d'options à limiter
4.0.0

Exemples

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

Ajouter des options d'attribut de métadonnées 'extra'

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

Comment utiliser ce code