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 Adjusting Query Args to List Results by Title (Shortcode)

Tagged: , ,

Viewing 4 posts - 1 through 4 (of 4 total)
  • Paul Lumsdaine
    #39253

    The documentation is kind of sparse in this area. Can I have an example of how I can modify the query args to ‘orderby’ => ‘title’?

    Ross Moderator
    #39398

    Hey Paul

    You don’t need to do this via query args – you can do all this via the posts tab.

    If it must be dynamic and via the query args, then its the same as when using the standard new WP_Query($args)

    https://www.designsandcode.com/documentation/search-filter-pro/action-filter-reference/#Edit_Query_Arguments

    So, to modify orderby you need this part of the WP docs:

    https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

    Updating the S&F filter example with the example from the WP site on order:

    $args = array(
    	'orderby' => 'title',
    	'order'   => 'DESC'
    );
    $query = new WP_Query( $args );

    Will update the filter like:

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

    Thanks

    Paul Lumsdaine
    #39454

    Thank you for this explanation.

    Do you need to have the sfid or can you make this apply to all posts using the search and filter plugin?

    I basically had to create separate filters for each custom taxonomy term (6 of them) but they all need to return alphabetical. Was trying to future proof by just having this apply to any filter used on a custom taxonomy page.

    Was able to find a function that modified the default query for all posts under that custom taxonomy to order by title.

    I guess overall I’ve struggled in figuring on how to combine and utilize different sets of filters based on the condition of a specific taxonomy term.

    -Paul

    Ross Moderator
    #39507

    Hey Paul

    You can remove the sfid stuff and it will apply to all S&F queries (not all queries in your site) – so I guess this would work how you want – however, you can just go to the posts tab in the search form edit screen, and change the default order to order them by title?

    If you wanted to order different queries in your site not just S&F ones, then you would use the WP filter pre_get_posts which works a little differently to the one above.

    Thanks

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

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