Created
February 25, 2015 12:34
-
-
Save jchristopher/0caa9d0f14e7e80bec95 to your computer and use it in GitHub Desktop.
Limit SearchWP results to a specific post type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function my_searchwp_limit_to_post_type( $clause, $engine ) { | |
global $wpdb; | |
if ( isset( $_GET['post_type'] ) ) { | |
$post_type = sanitize_text_field( $_GET['post_type'] ); | |
if ( post_type_exists( $post_type ) ) { | |
$clause = $wpdb->prepare( "AND {$wpdb->prefix}posts.post_type = %s", $post_type ); | |
} | |
} | |
return $clause; | |
} | |
add_filter( 'searchwp_where', 'my_searchwp_limit_to_post_type', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment