Skip to content

Instantly share code, notes, and snippets.

@imath
Last active December 11, 2015 09:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imath/4582027 to your computer and use it in GitHub Desktop.
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...
<?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;
}
?>
@cidadesonho
Copy link

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