I’m using woocommerce shortcode to display custom products loop, e.g. [products limit="-1" paginate="true" orderby="menu_order" columns="5" ids="85,11,1083,256,37,12,517,68,2577,104"]
. But there’s a problem – they are displaying sorted by title, but I need them to be sorted in that exact order they are in shortcode. I found no such option in shortcodes docs. Is there a way to achieve it with shortcode?
2
Answers
Solution found:
orderby = "post__in"
Source: Woocommerce Product Short Code Order by Order of IDs
The
woocommerce_shortcode_products_query_results
hook runs after the products have been queried from the database, but before they are displayed on the page. By hooking into this hook and modifying the order of the results, it is possible to display the products in the desired order.This code checks for the presence of the ids attribute in the shortcode and, if it exists, rearranges the products in the $results->ids array to match the order specified in the attribute. Source