Problem:
The customer wants to sort results based on the comments count.
Solution:
Upon further review, I identified that the comment_count field in the wp_posts table can be used directly for sorting. I provided a code snippet to add to the theme's functions.php file to sort by the comment_count field:
add_filter('wpv_filter_query', function($query, $setting, $view_id){ if (in_array($view_id, array(1234))) { $query['orderby'] = array('comment_count' => 'DESC'); } return $query; }, 101, 3);
Replace 1234 with the actual view's ID. This code sorts the results by the number of comments in descending order.
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | - |
- | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | - |
Supporter timezone: America/Sao_Paulo (GMT-03:00)
This topic contains 2 replies, has 2 voices.
Last updated by 4 months, 2 weeks ago.
Assisted by: Mateus Getulio.