Skip to content

Instantly share code, notes, and snippets.

@axxe16
Created January 29, 2020 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axxe16/93e8dbdf13480d6c8564062f68befe22 to your computer and use it in GitHub Desktop.
Save axxe16/93e8dbdf13480d6c8564062f68befe22 to your computer and use it in GitHub Desktop.
rendo ricercabile CPT #wp #search #customize
<?php
//aggiungo custom post type su cui effettuare la ricerca
function ek_add_post_type_to_search( $query ) {
if ( is_admin() || ! $query->is_main_query() ) {
return;
}
if ( $query->is_search() ) {
$query->set(
'post_type',
array(
'moduli'
)
);
}
}
add_filter( 'pre_get_posts', 'ek_add_post_type_to_search' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment