Looking to return each occurrence (product) found in name where name is comma separated, e.g. [woo_products_by_name name="shoe,shirt"] If I do not explode name then nothing is returned as only shoe,shirt is seen. If explode is used then the query is not selective and it appears that all products are returned. If only 'name' => $name is used and one verse two products as described above are specified, then the query works as expected. Would like to return a match for each item so in this example, to products would be returned.
function woo_products_by_name_shortcode( $atts, $content = null ) {
// Get attribuets
extract(shortcode_atts(array(
'name' => ''
), $atts));
//$name = explode(",", $atts['name']);
ob_start();
// Define Query Arguments
$loop = new WP_Query( array(
'post_type' => 'product',
'posts_per_page' => 10,
'name' => explode(",",$name)
));
// Get products number
$product_count = $loop->post_count;
echo '<pre>'; print_r($loop->posts); echo '</pre>';
return ob_get_clean();
}
add_shortcode("woo_products_by_name", "woo_products_by_name_shortcode");