I need a little help with some functionality. I am trying to create an Post Page that can be sort dynamically to show what posts the user would like to see
Use Scenario:
In the Post, there are 4 title ei: Title A, Title B, Title C and Title D.
Title A = CARAMOAN A LOOK BACK;
Title B = DESTINATION: PUERTO PRINCESA;
Title C = THE THINGS A FREE ROUND-TRIP TICKET CAN MAKE YOU SEE;
Title D = FIVE THINGS TO REMEMBER WHEN TRAVELING IN THE PHILIPPINES;
Now with this I want to sort by:
Most Comment
Most Viewed
Alphabetical – Ascending Order
which the user can change the page order by clicking on a Button that would look something like this.
The easiest way for that would be using a query string.
I’ll assume that you are looking at a category page.
First we will add the buttons to the category page
This adds a query string to the URL of the page, now on the top of the category page we will add this code:
After that we will create a function that will sort the posts for us in the functions.php template
Since we have 3 sort types, we could use a switch case or a if-else statement. I will use if-else here.
WordPress does not have a native view count, I used an instruction that i read here.
Since we have all the necessary functions and variables, we need to override the query.
You will edit the loop so it goes like this:
That’s it 🙂