Cum să filtrezi toate produsele după products_tag (WooCommerce)
23 nov. 2012, 17:07:30
Vizualizări: 21K
Voturi: 3
Încerc să preiau miniaturile doar pentru anumite produse din WooCommerce, folosind products_tag
,
acest cod afișează toate produsele:
<ul class="products">
<?php
$args = array( 'post_type' => 'product', 'posts_per_page' => 5 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
<?php global $post; echo "<p id = 'id_name'>" . $thePostID = $post->ID. " </p>"; ?>
<?php if (has_post_thumbnail( $loop->post->ID ))
echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog');
else echo '<img src="'.$woocommerce->plugin_url().'/assets/images/placeholder.png" alt="Imagine substitut" width="'.$woocommerce->get_image_size('shop_catalog_image_width').'px" height="'.$woocommerce->get_image_size('shop_catalog_image_height').'px" />';
?>
<?php endwhile; ?>
</ul><!--/.products-->
Am încercat să adaug mai multe argumente în array inserând 'product_tag' dar nu funcționează:
$args = array( 'post_type' => 'product', 'posts_per_page' => 5, product_tag => 'shoes' );
Cum pot afișa doar produsele cu eticheta shoes?
Mulțumesc pentru ajutor

Rodrigo Sanz
485
Toate răspunsurile la întrebare
2
0
Acest lucru este menționat în documentație
$args = array(
'tag' => array( 'excellent', 'modern' ), // Etichetele produselor
);
$products = wc_get_products( $args ); // Obține produsele în funcție de argumente
https://github.com/woocommerce/woocommerce/wiki/wc_get_products-and-WC_Product_Query

Dev Abhi
115
6 feb. 2023 10:38:29
Întrebări similare
2
răspunsuri