0

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;

}

Any ideas on how to get this thing to work?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.