Forums › Forums › Search & Filter Pro › Adjusting Query Args to List Results by Title (Shortcode)
- This topic has 3 replies, 2 voices, and was last updated 8 years, 7 months ago by Ross.
-
Ross Moderator(Private) March 14, 2016 at 5:20 pm #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)
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
Anonymous(Private) March 15, 2016 at 4:33 pm #39454Thank 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(Private) March 16, 2016 at 9:33 am #39507Hey 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
-
AuthorPosts