Woocommerce:使用参数

时间:2017-05-16 06:24:06

标签: php wordpress woocommerce

我正在尝试创建一个短代码来获取woocommerce中特定类别的产品。我正在使用' tax_query'定位特定类别和' shortcode_atts'从短代码本身获取参数。代码如下:

function quick_launch_products($atts) {

    extract(shortcode_atts(array(
        'product_category_ID' => '',
    ), $atts));

    $args = array(
        'post_type'             => 'product',
        'post_status'           => 'publish',
        'ignore_sticky_posts'   => 1,
        'posts_per_page'        => '12',
        'meta_query'            => array(
            array(
                'key'           => '_visibility',
                'value'         => array('catalog', 'visible'),
                'compare'       => 'IN'
            )
        ),
        'tax_query'             => array(
            array(
                'taxonomy'      => 'product_cat',
                'field'         => 'term_id',
                'terms'         => $product_category_ID,
                'operator'      => 'IN'
            )
        )
    );

    echo $product_category_ID;

    $products = null;
    $products = new WP_Query($args);
}        
add_shortcode("quick_launch_product_slider", "quick_launch_products");

短代码:

[quick_launch_product_slider product_category_ID="383"]

返回值为空。我看到了很多演示代码,并且完全按照原样进行操作,但它根本不起作用。

我在这里缺少什么? 提前谢谢。

0 个答案:

没有答案