Forums Forums Search & Filter Pro A third sort order?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Trevor
    #242759

    You would need to return the sort order settings in the Posts tab back to default, and instead see if you can use this filter:

    https://searchandfilter.com/documentation/action-filter-reference/#edit-query-arguments

    This filter uses the same argument structure as wp_query.

    Anonymous
    #242855

    Thank you. I restored the Posts settings to the default order and used the following code, which is not affecting the sort order:

    
    function filter_function_name( $query_args, $sfid ) {
    	
    	if($sfid==23142) {
    	
    		$query_args["orderby"] = array(
            	'subject_code'       => 'asc',
            	'course_number'       => 'asc',
    			'start_date'     => 'asc',
    		);				
    	}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );

    It works if I set just a single order like so:

    
    function filter_function_name( $query_args, $sfid ) {
    	
    	if($sfid==23142) {
    	
    		$query_args["orderby"] = 'subject_code';		
    	}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );

    Do I need to format the $query_args differently? That’s how I do it in a regular WP_Query…

    Thank you!

    Anonymous
    #242872

    Nevermind. I didn’t realize I had to also manually add the meta_query to get the search order to work. Here is my working code:

    function filter_function_name( $query_args, $sfid ) {
    	
    	//if search form ID = 225, the do something with this query
    	if($sfid==23142) {
    		
    	     $query_args["meta_query"] = array(
    	        'relation' => 'AND',
    	        'subject_code' => array(
                    'key'       => 'subject_code',
                    'compare'   => 'EXISTS',
                ),
                'course_number' => array(
                    'key'       => 'course_number',
                    'compare'   => 'EXISTS',
                ),
                'start_date' => array(
                    'key'       => 'start_date',
    		'compare'   => 'EXISTS',
                ),
    	    );
    	    
    		$query_args["orderby"] = array(
            	'subject_code'       => 'asc',
            	'course_number'       => 'asc',
            	'start_date'       => 'asc',
    		);				
    	}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
    

    Please feel free to close this ticket. Thank you!

    Trevor
    #242881

    Thanks for sharing. I will close this thread for now.

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