Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
adds some categories to BP Default header search (dropdown options) in order to search within this categories...
<?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;
}
?>

I wish display a new post type, is there a way? Thanks :*

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