// 販売中の曲だけの表示
function get_instock_products() {
global $post;
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id', //This is optional, as it defaults to 'term_id'
'terms' => 51,
'operator' => 'IN' // Possible values are 'IN', 'NOT IN', 'AND'.
),
array(
'taxonomy' => 'product_visibility',
'field' => 'slug',
'terms' => 'exclude-from-catalog', // Possibly 'exclude-from-search' too
'operator' => 'NOT IN'
)
),
'meta_query' => array(
array(
'key' => '_stock_status',
'value' => 'instock'
),
array(
'key' => '_backorders',
'value' => 'no'
),
)
);
$products = get_posts($args);
do_action( 'woocommerce_before_shop_loop' );
$html .= woocommerce_product_loop_start();
foreach($products as $post): // ループの開始
setup_postdata($post); // 投稿のセットアップ
$html .= wc_get_template_part( 'content', 'product' );
endforeach; // ループの終了
$html .= woocommerce_product_loop_end();
return $html;
}
add_shortcode( 'instock_products' , 'get_instock_products' );