I have a page that by default lists posts by chronological order. After the page is loaded, I want the user to be able to click on a button that will sort the posts by author alphabetically, then back to chronologically if desired. Is there a way to do this without sending a new query each time?
Asked
Active
Viewed 20 times
1 Answers
1
Yes and no,
As long as your blogs are all loaded at once (no pagination) this should be possible with javascript.
However if you are using pagination only the blogs shown on the page you are showing are loaded there for a new query is required each time. This can be done either by a full page reload, or asynchronous using a ajax call.

Jasper B
- 851
- 4
- 13
-
There is no pagination. So how would I accomplish this? My javascript knowledge is very limited. Thanks. – Kristi Perkins Jan 11 '21 at 16:47
-
1It would require some knowledge / understanding of javascirpt, and knowledge of customization of your template files. for the javascript you could implement something like suggested in this post [link](https://stackoverflow.com/questions/45927868/sorting-a-div-based-on-data-attribute-in-jquery). for the data-attributes you have to customize the template to contain both category and author name to be able to sort by those fields. – Jasper B Jan 12 '21 at 16:28
-
Thanks, that link helped. – Kristi Perkins Jan 12 '21 at 17:40