WordPress 3.5 came out with an awesome feature of ordering by
post__in (Codex). So when I got to my current issue, I noticed that I could not use the default orderby options (alphabetical title, ID, etc.), so the code used to create the
post__in orderby can also be extended to be used for
get_terms, which by default is not available in WordPress core. However, there is a great filter to enable this (see WordPress ticket).
So, first, I need to setup the function. In this scenario, I am using WooCommerce, but it could work with any theme, or ecommerce solution. For more information on get_terms() please see the WordPress Codex.
In this code, I use
wps_category_image() which outputs the WooCommerce category image.
Next, is the really cool part. You want to filter the get_terms_orderby SQL.
First, you need to check to see if include is the preferred orderby argument.
Second, you want to sanitize it with
Third, set the order to the FIELD include (see here for more information).