You have filtered your post list and now you want also sort it? That will be no problem. We support sort by Date, Title and random. And there can be more possibilities. You can get all sorts which comes with WordPress Orderby-parameters. It may useful to sort about ‘modified’ – order by last modified date rather than ‘date’ – the publish date or similar posts out of the same category should distinguish more relevant by ‘comment_count’, if you have allowed commenting.
Everything to do
Use the predefined example. We talk about just add a method for the filter ‘cpwp_possible_sorts’ (in our example Sort-by add-on it’s at line 54) and build-up the code as PHP file to use it as an add-on.
- Download our example Sort-by add-on file from GistHub
- Write your orderby-parameter(s) you can find at the developer.wordpress.org website to the option list in line 48 to 49
- Upload the file as a normal widget with the admin pages or use a FTP client
- Optional: Change the add-on name (Plugin name) and description text in the header of the file in line 3 to 8
- Activate the Add-on as a normal widget
- Go to Term and Category based Posts Widget > Filter tab > choose your new sort option entry
Here you expand just one wp_query parameter, orderby. But it will be very effizient.
Take your time for a look at the wide field of the loop
To get more effective advantages from the loop there is another filter it is possible to manipulate the hole wp_query with an added filter ‘cpwp_query_args’ in line 36 of our Sort-by example.