Skip to content

Instantly share code, notes, and snippets.

@mikeislearning
Last active August 29, 2015 14:24
Show Gist options
  • Save mikeislearning/91b65c97bbc866bb5579 to your computer and use it in GitHub Desktop.
Save mikeislearning/91b65c97bbc866bb5579 to your computer and use it in GitHub Desktop.
Unable to filter with searchwp
# require_once('library/wp-advanced-search/wpas.php');
// Check for Taxonomy Term
function pa_in_taxonomy($tax, $term, $_post = NULL) {
if ( !$tax || !$term ) { return FALSE; }
if ( $_post ) {
$_post = get_post( $_post );
} else {
$_post =& $GLOBALS['post'];
}
if ( !$_post ) { return FALSE; }
$return = is_object_in_term( $_post->ID, $tax, $term );
if ( is_wp_error( $return ) ) { return FALSE; }
return $return;
}
define( 'WPE_GOVERNOR', false );
function my_searchwp_include_only_category( $ids, $engine, $terms ) {
// if and only if a category ID was submitted:
// we only want to apply this limitation to the default search engine
// if you would like to change that you can do so here
if ( ! empty( $_GET['drm-tax-content-type'] ) && 'default' == $engine ) {
$content_type = $_GET['drm-tax-content-type'];
$args = array(
'category' => $content_type,
'fields' => 'drm-tax-content-type',
#'post_type' => 'drm-archive',
);
$ids = get_posts($args);
// if there were no posts returned we need to force an empty result
if ( 0 == count( $ids ) ) {
$ids = array( 0 ); // this will force SearchWP to return zero results
}
}
// always return our $ids
return $ids;
}
add_filter( 'searchwp_include', 'my_searchwp_include_only_category', 10, 3 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment