Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Last active October 30, 2019 12:50
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 jchristopher/dd1a9ea4ec43eda4e3c565a38b895ef1 to your computer and use it in GitHub Desktop.
Save jchristopher/dd1a9ea4ec43eda4e3c565a38b895ef1 to your computer and use it in GitHub Desktop.
<?php
function my_searchwp_engine_settings_default( $settings, $query ) {
if ( empty( $_REQUEST['post_type'] ) ) {
return $settings;
}
$post_type_limiter = $_REQUEST['post_type'];
if ( ! post_type_exists( $post_type_limiter ) ) {
return $settings;
}
// limit results to one post type
foreach ( $settings as $post_type => $post_type_settings ) {
// account for (i.e. skip) the search engine label storage
if ( 'searchwp_engine_label' === $post_type ) {
continue;
}
$settings[ $post_type ]['enabled'] = ( $post_type == $post_type_limiter ) ? true : false;
}
return $settings;
}
add_filter( 'searchwp_engine_settings_default', 'my_searchwp_engine_settings_default', 10, 2 );
@josephbuarao
Copy link

Hi @jchristopher

We are using your plugin in our website but we wanted to limit the search results in one custom post type. How we can override the search logic via functions.php in our theme? Please advise.

Thank you very much.

@jchristopher
Copy link
Author

For support please open a ticket using the Support tab on the SearchWP settings screen, thank you!

@josephbuarao
Copy link

josephbuarao commented Oct 30, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment