#2356 closed enhancement (fixed)
bbp_has_search_results -> abord query if empty search terms = problems ?
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 2.5 | Priority: | normal |
| Severity: | normal | Version: | 2.3.2 |
| Component: | Component - Search | Keywords: | needs-patch |
| Cc: |
Description
Hi, in the function bbp_has_search_results(), there is this line :
// Don't bother if we don't have search terms if ( empty( $r['s'] ) ) return false;
This is, I think, a mistake :
I made a plugin that modify the bbPress query to fetch geolocated topics.
I would like results to be returned even if there is no search terms; if the user is "geo-searching" posts : it would then retrieve the last posts matching.
Maybe this line of code could be written in a different way !
eg.
// Don't bother if we don't have search terms
if ( empty( $r['s'] ) ) && (apply_filters('bbp_abord_if_empty_search_terms',true,$r)==true)
return false;
Not very clean, but that's the idea...
Change History (5)
#2
@
12 years ago
- Keywords needs-patch added
- Milestone changed from Awaiting Review to 2.5
Similar enough to #2355 where I think breaking apart bbp_parse_query() will address this.
Note: this is not exclusive to search, and happens when querying any other forum data.
Moving to 2.5.
#3
@
12 years ago
- Owner set to johnjamesjacoby
- Resolution set to fixed
- Status changed from new to closed
In 5162:
#4
@
11 years ago
Yeah, this is better;
But still, I have to run twice the query (if no search terms) :
- run the regular query (gets empty results)
-filter bbp_has_search_results
- run another query
This is heavy.
I still think my solution could help :
$has_search_terms = ( !empty( $r['s'] ) );
$do_search_query = apply_filters('bbp_do_search_query',$has_search_terms,$r);
if ( $do_search_query ) ) {
$bbp->search_query = new WP_Query( $r );
}
Meanwhile, I did this :
add_filter('bbp_before_has_search_results_parse_args', array(&$this,'bbpress_identify_search_query')); add_filter('bbp_after_has_search_results_parse_args', array(&$this,'bbpress_add_dummy_keyword')); add_action('pre_get_posts',array(&$this,'bbpress_remove_dummy_keyword')); function bbpress_identify_search_query($args){ $args['is_bbp_search']=true; return $args; } function bbpress_add_dummy_keyword($args){ if(!$args['s']) $args['s']='bbptl-dummy-term'; //see https://bbpress.trac.wordpress.org/ticket/2356 return $args; } function bbpress_remove_dummy_keyword($query){ if(!$query->get('is_bbp_search')) return $query; $search_terms = $query->get('s'); if(!$search_terms) return $query; if($search_terms!='bbptl-dummy-term') return $query; $query->set('s',false); return $query; }