我不知道为什么我不能按类别名称取产品。我找不到任何产品。代码如下所示
<ul class="glide__slides">
<?php
$args = array(
\'post_type\' => \'product\',
\'category_name\' => \'trofee\',
\'posts_per_page\' => 20,
\'meta_query\' => array(
\'relation\' => \'OR\',
array( // Simple products type
\'key\' => \'_sale_price\',
\'value\' => 0,
\'compare\' => \'>\',
\'type\' => \'numeric\'
),
array( // Variable products type
\'key\' => \'_min_variation_sale_price\',
\'value\' => 0,
\'compare\' => \'>\',
\'type\' => \'numeric\'
)
)
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
global $product;
$id = $product->get_id();
echo \'<li class="glide__slide">\';
echo \'<br /><a href="\'.get_permalink().\'">\' . woocommerce_get_product_thumbnail().\' <br> \'.get_the_title(). \'<br>\' . \'<div class="bf-sale"><span>\' . $product->get_regular_price() .\' Lei </span>\' . \'<span>\' . $product->get_sale_price() .\'Lei</span></div>\' .\'</a>\';
echo \'<div class="trophies-container__trophy-action">\';
echo sprintf(\' <a href="?add-to-cart=%d data-quantity="1" class="button product_type_simple add_to_cart_button ajax_add_to_cart" data-product_id="%d" data-product_sku="" rel="nofollow"><i class="fas fa-shopping-cart"></i>Adaugă în coș</a>\',$id,$id);
echo \'</div>\';
echo \'</li>\';
endwhile;
} else {
echo __( \'No products found\' );
}
wp_reset_postdata();
?>