Ich habe WooCommerce auf Version 3.0 aktualisiert, kann aber die vorgestellten Produkte zu meinem Thema nicht anzeigen. Ich habe eine Weile gegoogelt und WC hat das _Feature gelöscht und dies in Taxonomie hinzugefügt. Aber ich verstehe nicht so sehr, wie mein Thema die vorgestellten Produkte bekommt.
Hier ist der Code der falsch vorgestellten Produkte.
$meta_query = WC()->query->get_meta_query();
$meta_query[] = array(
'key' => '_featured',
'value' => 'yes'
);
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => $products,
'orderby' => $orderby,
'order' => $order == 'asc' ? 'asc' : 'desc',
'meta_query' => $meta_query
);
Und wenn Sie wissen, wo sich das vorgestellte Element in der Datenbank befindet. Vielen Dank.
Seit Woocommerce 3 müssen Sie eine Steuerabfrage verwenden, stattdessen als empfohlene Produkte werden jetzt von product_visibility
benutzerdefinierter Taxonomie für den Begrifffeatured
behandelt. :
// The tax query
$tax_query[] = array(
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => 'featured',
'operator' => 'IN', // or 'NOT IN' to exclude feature products
);
// The query
$query = new WP_Query( array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => $products,
'orderby' => $orderby,
'order' => $order == 'asc' ? 'asc' : 'desc',
'tax_query' => $tax_query // <===
) );
Verweise:
WP_Query
TaxonomieparameterWC_Shortcodes
featured_products()
functionSie könnten
wc_get_featured_product_ids()
function verwenden, um das Array mit den empfohlenen Produkt-IDs abzurufen aber die Verwendung einer Steuerabfrage in einemWP_Query
ist in Ordnung und der richtige Weg…
Verbunden:
Es sollte funktionieren.
Dies ist eine alte Frage, aber Sie können auch wc_get_featured_product_ids () verwenden:
$args = array(
'post_type' => 'product',
'posts_per_page' => $products,
'orderby' => $orderby,
'order' => $order == 'asc' ? 'asc' : 'desc',
'post__in' => wc_get_featured_product_ids(),
);
$query = new WP_Query( $args );
Habe es gerade hier entdeckt. Ich hoffe, es hilft!
$args = array(
'post_type' => 'product',
'posts_per_page' => 12,
'tax_query' => array(
array(
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => 'featured',
),
),
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
wc_get_template_part( 'content', 'product' );
endwhile;
} else {
echo __( 'No products found' );
}
wp_reset_postdata();