我有一个简码,我想从特定的Woocommerce类别获得所有产品。按照产品类别在WooCommerce的简码中获取产品
add_shortcode('list-products', 'prod_listing_params');
function prod_listing_params($atts) {
ob_start();
extract(shortcode_atts(array (
'type' => 'product',
'order' => 'date',
'orderby' => 'title',
'posts' => -1,
'category' => '',
), $atts));
$options = array(
'post_type' => $type,
'order' => $order,
'orderby' => $orderby,
'posts_per_page' => $posts,
'product_cat' => $product_cat,
);
$query = new WP_Query($options);
if ($query->have_posts()) { ?>
<div class="#">
<?php while ($query->have_posts()) : $query->the_post(); ?>
<p class="#">
<span id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</span></p>
<?php endwhile;
wp_reset_postdata(); ?>
</div>
<?php
$myvar = ob_get_clean();
return $myvar;
}
}
于是我就用短码:
[list-products category="shoes"]
但是,尽管在短码提供的类别返回全部来自所有类别产品。
我该如何修改这个以获得分类?
感谢
完美!谢谢 –