I would like to order the product display by the ids that are entered in [products ids=””] short code. I need it to order by the order you enter it. So… [products ids=”1,2,3″] [products ids=”3,1,2″] [products ids=”2,3,1″] … all list differently.
I found this piece of code that I think is close but doesn’t quite work. I’m not real familiar with this method so I am not sure what is wrong.
add_filter( 'woocommerce_shortcode_products_query', 'woocommerce_shortcode_products_orderby' );
function woocommerce_shortcode_products_orderby( $args ) {
$standard_array = array('menu_order','title','date','rand','id');
if( isset( $args['orderby'] ) && !in_array( $args['orderby'], $standard_array ) ) {
$args['orderby'] = 'post__in';
}
return $args;
I read up on post__in but not sure how it gets the ID list I entered. Is there another/better way to grab that id list and use it for the order?
Any ideas on how to get this thing to work?
2
Answers
Just add order by in your shortcode like –
Update from 2020.
The products shortcode can’t handle this orderby
So you can create your own foreach loop: