Forums › Forums › Search & Filter Pro › Sort order – different query
Tagged: queries, sort order
- This topic has 5 replies, 2 voices, and was last updated 6 years, 5 months ago by Anonymous.
-
Anonymous(Private) June 21, 2018 at 8:06 am #180917
Hi!
We have a Sort Order UI element in our search form. Currently it has 4 options: 1. Most Popular 2. Most Commented 3. Newests 4. Oldests. It works perfectly, but we want to do the following thing: we want to replace Newests and Oldests with a “By Date” option. It’s easy, but here is our problem: In this case we want to show the posts grouped by month and year.
Example:
2018 March
– Post title
– Post title
– Post title
2018 February
– Post title
– Post title
– Post title
– Post title
2018 January
– Post title
– Post title
and so on and so forth.Is it possible to use different queries for the different sort by dropdown options?
Thanks!
Trevor(Private) June 21, 2018 at 3:55 pm #180967It may be. You may need to use our filters. For ordering, I think you will need to use our Edit Query Arguments filter to modify the sort order argument when the date one is chosen.
Then, use Filter Input Object (on the same documentation page) to change the way the terms are listed/indented.
Anonymous(Private) June 25, 2018 at 10:31 am #181142Thanks Trevor, but I’m not sure if I communicated my question properly, so this time I use screenshots to show you what result I want.
Now our search result page look like this: http://screenshot.co/#!/3dfa83767f
If I choose “Most Popular”, it lists all of the articles without any grouping. That’s fine.I can modify the s&f template file so it lists the post grouped by months and year: http://screenshot.co/#!/3dfa83767f But I only want to use this template if the user chooses “By Date” from the Sort order dropdown and in any other case I want the simple list without grouping.
Anonymous(Private) June 25, 2018 at 10:33 am #181144Sorry, the second screenshot is wrong. Wanted to show you this one: http://screenshot.co/#!/cd9a38462d
Trevor(Private) June 25, 2018 at 12:31 pm #181171You could use PHP to look at the array that holds the filter arguments, and conditionally load different code in the same template. Again, that is custom coding.
To start with, put this code on the results page in a suitable place:
$sf_current_query_array = $searchandfilter->get(1446)->current_query()->get_array(); echo '<pre>'; print_r($sf_current_query_array); echo '</pre>';
CHANGE THE ID NUMBER in the above code (1446) to whatever the ID of you form is.
You will then see the array of filters used, and you can figure than how to fetch the value you need to add PHP to your template to test what the user has selected.
-
AuthorPosts