Last active
December 11, 2015 09:48
-
-
Save imath/4582027 to your computer and use it in GitHub Desktop.
adds some categories to BP Default header search (dropdown options) in order to search within this categories...
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 | |
/*** based on http://buddydev.com/buddypress/making-buddypress-activity-searchable/ ***/ | |
/* simply paste what follows in your functions.php file */ | |
add_filter( 'bp_search_form_type_select_options', 'kendyman_seventeen_options', 10, 1); | |
function kendyman_seventeen_options( $options ) { | |
$args = array( | |
'orderby' => 'name', /* ou id ou count .. */ | |
'order' => 'ASC', /* ou DESC */ | |
'include' => array( 1, 5 ) /* list of category ids to include */ | |
); | |
$cats = get_terms( 'category', $args ); | |
foreach( $cats as $term ){ | |
$options['cat-'.$term->term_id] = $term->name; | |
} | |
return $options; | |
} | |
add_filter('bp_core_search_site', 'kendyman_seventeen_search_by_cat_url', 10, 2); | |
function kendyman_seventeen_search_by_cat_url( $url, $search_terms ){ | |
$search_which = $_POST['search-which']; | |
if( strpos( $search_which, 'cat-' ) !== false ) { | |
$search_query = str_replace('-', '=', $search_which ); | |
$url = site_url( '/?s='. urlencode( $search_terms ) .'&'. $search_query ); | |
} | |
return $url; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wish display a new post type, is there a way? Thanks :*