Per impostazione predefinita, la ricerca di WordPress mostrerà solo i tuoi post del blog. Puoi anche aggiungere gli altri tipi di post alla ricerca per ampliarla.
Istruzioni: Aggiungi il seguente codice al file functions.php del tuo tema WordPress per includere tutti i tipi di post nella tua ricerca.
<?php
function pippin_include_post_types_in_search($query) {
if(is_search() && is_main_query()) {
$post_types = get_post_types(array('public' => true, 'exclude_from_search' => false), 'objects');
$searchable_types = array();
if($post_types) {
foreach( $post_types as $type) {
$searchable_types[] = $type->name;
}
}
$query->set('post_type', $searchable_types);
}
return $query;
}
add_action('pre_get_posts', 'pippin_include_post_types_in_search');
?>
Potrebbe interessarti anche disabilitare la ricerca pubblica in WordPress e filtrare la ricerca per utenti in WordPress.
Commenti Lascia una risposta