How to randomize selected products?
-
Hello!
I created the filter below to display 3 products via a custom short code on my home page. It works however I would like to know if it is possible to extend the filter’s functionality so that it will randomly return 3 products instead of always returning the same ones.
Thank you.
add_shortcode( 'in_stock_products', 'rompre_in_stock_products_shortcode' ); function rompre_in_stock_products_shortcode() { $args = array( 'post_type' => 'product', 'posts_per_page' => 3, 'post_status' => 'publish', 'meta_query' => array( array( 'key' => '_stock_status', 'value' => 'instock', ) ), 'fields' => 'ids', ); $product_ids = get_posts( $args ); $product_ids = implode( ",", $product_ids ); return do_shortcode("[products ids='$product_ids']"); }
The page I need help with: [log in to see the link]
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘How to randomize selected products?’ is closed to new replies.