Forums Forums Search & Filter Pro Null Fields Not Returning Results

Viewing 10 posts - 1 through 10 (of 11 total)
  • Anonymous
    #98567

    Hi,

    Thanks for the great plugin, I’m just having a small issue and hoping you can help.

    We have a search form that searches several fields within a post. For certain posts values are not completed.

    The issue being that the range fields are being submitted as part of the search query regardless as to whether the user has interacted with them. The posts that do not include the range field at all are then not being returned.

    e.g. one of the range fields is “Age” with the minimum set to 5 and the max set to 100. When the user alters another search field the “Age” variable is included in the search URL:

    _sfm_age=5+70

    The issue being any fields that do not have a value set for age are not returned at all.

    Is there a way around this?

    I can provide a link to the example via private message if this would help.

    Thanks,
    Joe

    Trevor
    #98669

    I understand the issue, and there is no simple way around the problem. In the next major version (V3) the range functionality will probably have a checkbox in settings to ‘Include NULL value posts in search results’.

    For now all you can do is to intercept the search parameters, check if the range is at the default values, and remove that from the query, using PHP. See the Edit Query Arguments documentation (there may well be other snippets of the forum).

    Anonymous
    #98673

    Thanks Trevor.

    Any ideas on the release time of the new version?

    Trevor
    #98678

    All I can say is that Ross is working on it and has been for many weeks already. It is a big project, so I would say more than two months at least.

    Anonymous
    #98688

    Thanks Trevor. Great plugin and support! 🙂

    Anonymous
    #98705

    Sorry to bother you, I’m trying to modify the query, however the $query_args[‘meta_query’] is returning a blank array whenever I print it out. This is even after I have altered a field and submitted the form.

    function remove_default_range( $query_args, $sfid ) {
    	
    	//if search form ID = 225, the do something with this query
    	if($sfid==25 && $query_args)	{
    		if((isset($query_args['meta_query']))&&(is_array($query_args['meta_query']))) {
          print_r($query_args['meta_query']);
    		}			
    	}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'remove_default_range', 20, 2 );
    Trevor
    #98734

    So, it is trying to print something but the array is empty, or nothing prints? Did you try to simply output the query_args array?

    Anonymous
    #98753

    Yes, I did:

    print_r($query_args['meta_query']);

    To confirm what variables I needed to alter.

    Trevor
    #98769

    It is a while since I looked at the array, but I think I did something like this:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(25)->current_query()->get_array();
    echo "<pre>";
    print_r($sf_current_query);
    echo "</pre>";
    Anonymous
    #98807

    Wooo, that got it. Thank you for your patience.

    For anyone else with this issue please see my code below. Probably not perfect but it works. 🙂

    // Exclude the default range values from the search as they are meaning the search returns no results
    
    function remove_default_range( $query_args, $sfid ) {
    	
    	//if search form ID = 225, the do something with this query
    	if($sfid==25 && $query_args)	{
    		if((isset($query_args['meta_query']))&&(is_array($query_args['meta_query']))) {
    			global $searchandfilter;
    			$sf_current_query = $searchandfilter->get(25)->current_query()->get_array();
    			/* echo "<pre>";
    			print_r($sf_current_query);
    			echo "</pre>";*/
    
    			echo $sf_current_query['_sfm_minimum_per_round'][0]['value'];
    
    			if($sf_current_query['_sfm_minimum_per_round'][0]['value'] == '0' && $sf_current_query['_sfm_minimum_per_round'][0]['value'] == '50000') {
    				unset($sf_current_query['_sfm_minimum_per_round']);
    			}
    
    			if($sf_current_query['_sfm_minimum_per_season'][0]['value'] == '0' && $sf_current_query['_sfm_minimum_per_season'][0]['value'] == '1000000') {
    				unset($sf_current_query['_sfm_minimum_per_season']);
    			}
    
    		}			
    	}
    
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'remove_default_range', 20, 2 );
Viewing 10 posts - 1 through 10 (of 11 total)