We have built a view for a product category (WooCommerce Shop) that works well so far. Filters, sorting, output, all on a good way - although it would have been very helpful to place the sorting independently from the filters - but that's another matter. Now to our concrete request:
The sorting should contain:
1. standard (menu_order)
2. price ascending (field-views_woo_price / ascending)
3. price descending (field-views_woo_price / descending)
Is it possible to realize this sorting in one call ([wpv-sort-orderby])? Or does it always need [wpv-sort-order]? Unfortunately, the latter makes no sense at all with the standard sorting. Also the two dropdowns next to each other are not very user-friendly ...
Do you have an idea for us?
Regards
Hello,
Unfortunately, there isn't such kind of built-in feature within Toolset, you can pass only one "wpv_sort_orderby" URL parameter to Views, so it is not possible to sort the result by two fields at the same time.
In your case, you might consider custom codes, for example, use action hook "pre_get_posts" in your shop page:
https://developer.wordpress.org/reference/hooks/pre_get_posts/
And follow WP document to customize the "orderby" parameter of WP_Query:
https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters
See the example in above document:
https://developer.wordpress.org/reference/hooks/pre_get_posts/#div-comment-2571
Hi Luo,
i don't want to sort the result by two fields at the same time. I want a Dropdown with different parameters, and sorting after selection:
1. standard (menu_order)
2. price ascending (field-views_woo_price / ascending)
3. price descending (field-views_woo_price / descending)
So always sort by one parameter, but one ascending, once descending ...
Is there any possibility?
Unfortunately, there isn't such kind of built-in feature, as a workaround, you can use custom codes to setup the Dropdown you mentioned above, and pass two URL parameters to views:
- wpv_sort_orderby (Field name)
- wpv_sort_order (Sort order)
- wpv_view_count (This is Toolset WordPress Archive ID)
For example:
hidden link