Skip to:
Content

bbPress.org

Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#2356 closed enhancement (fixed)

bbp_has_search_results -> abord query if empty search terms = problems ?

Reported by: grosbouff Owned by: johnjamesjacoby
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)

#1 @grosbouff
8 years ago

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;
        }

#2 @johnjamesjacoby
8 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 @johnjamesjacoby
8 years ago

  • Owner set to johnjamesjacoby
  • Resolution set to fixed
  • Status changed from new to closed

In 5162:

Allow 'bbp_has_search_results' filter to still run even if no search terms were passed. This brings it inline with other component queries. Fixes #2356.

#4 @grosbouff
7 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 );
	}

#5 @netweb
7 years ago

grosbouff,

Thanks for your update, though because this ticket is on a closed milestone and has been fixed (the code changes were included in bbPress 2.5) could you please create a new ticket with your proposed changes and reference this ticket.

Note: See TracTickets for help on using tickets.