Support Forums

The forums are closed and will be removed when we launch our new site.

Looking for support? You can access the support system via your account.

Forums Forums Search & Filter Pro Edit Query Arguments Not Working

Viewing 6 posts - 1 through 6 (of 6 total)
  • Alex Krijanovski
    #222024

    Hello!

    I’m having some trouble editing the search query. I’m using the plugin alongside Relevanssi and want results to be sorted by relevance as well as post_date or modified date. I tried adding this to the functions file

    function filter_function_name( $query_args, $sfid ) {
    
    	//if search form ID = 225, the do something with this query
    	if($sfid==5671)
    	{
    		//modify $query_args here before returning it
    		$query_args['orderby'] = 'post_date';
    	}
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );

    But it doesn’t amend the search URL or results.

    Any help would be greatly appreciated!

    Trevor Moderator
    #222075

    Did you try using the Post Date sorting option in the Posts settings tab of the form?

    With your code, I am not sure if one is overriding the other. I will need to ask the developer, Ross, what happens in this situation, and if it can be done.

    Let me know the answer to my question, and then we will see where we need to go from there?

    Alex Krijanovski
    #222161

    Thanks for your reply Trevor.

    I tried that and it doesn’t affect the order of the results. If I append “&orderby=post_date&order=desc” to the search results URL it sorts the results. Is there any way add that string to a search submit on a specific search box?

    Trevor Moderator
    #222185

    You could use a wordpress re-write to do that, but it must be another plugin or the theme that is overriding our sort.

    Alex Krijanovski
    #222197

    I added global $wp_query; var_dump($wp_query->query_vars); to the search results page and it looks like it’s picking up some of it but as a string rather than array:

    ["orderby"]=> string(8)

    Is the code I’ve added to the functions file in the correct format?
    $query_args['orderby'] = 'post_date';
    As it’s picking up the “orderby” but not the value “post_date”.

    Trevor Moderator
    #222359

    Try either:

    $query_args['orderby'] = 'date';

    or

    $query_args['orderby'] = 'publish_date';

Viewing 6 posts - 1 through 6 (of 6 total)

The forum ‘Search & Filter Pro’ is closed to new topics and replies.