SearchWP Documentation

Visualizza la guida all'installazione, sfoglia la Knowledge Base, scopri i numerosi hook di SearchWP

searchwp\query\mods

Da: 4.0.0

Personalizza i \SearchWP\Mod applicati durante una ricerca.

Nota: Ci sono alcuni \SearchWP\Mod interni che potrebbero essere presenti per la query. Questo hook non consente il filtraggio di tali \SearchWP\Mod critici per il funzionamento, ma solo dei \SearchWP\Mod definiti dall'utente.

Vedi anche searchwp\query\do_source_db_where per i dettagli interni.

Parametri

Tipo Parametro Predefinito Da
\SearchWP\Mod[] $mods [] 4.0.0
\SearchWP\Query $query La Query in esecuzione 4.0.0

Esempi

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

Crea Mod per escludere l'ID post 145 e l'ID post 211

<?php
add_filter( 'searchwp\query\mods', function( $mods, $query ) {
// Retrieve Source name to use with Mod.
$source = \SearchWP\Utils::get_post_type_source_name( 'post' );
// Build Mod to exclude Post ID 145 and Post ID 211.
$mod = new \SearchWP\Mod( $source );
$mod->set_where( [ [
'column' => 'id',
'value' => [ 145, 211 ],
'compare' => 'NOT IN',
'type' => 'NUMERIC',
] ] );
$mods[] = $mod;
return $mods;
}, 20, 2 );
// Execute search for 'coffee' using Mod enqueued above.
$search = new \SearchWP\Query( 'coffee' );
$results = $search->results; // Array of results.

Come usare questo codice