2 回答

TA貢獻(xiàn)1790條經(jīng)驗(yàn) 獲得超9個(gè)贊
您可以使用未記錄的參數(shù)“author”在 WC_Query 中簡(jiǎn)單地按作者 ID 獲取產(chǎn)品,如下所示:
$products = wc_get_products( array(
'status' => 'publish',
'limit' => -1,
'author' => get_current_user_id()
) );
你將得到一個(gè)WC_Product對(duì)象數(shù)組

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超6個(gè)贊
您可以像這樣使用自定義查詢
<?php
$authorID = get_the_author_meta('ID');
$args = array(
'post_type' => 'product',
'post_status' => 'publish'
'posts_per_page' => 12,
'product_cat' => 'pants'
'author' => $authorID
);
$loop = new WP_Query( $args );
?>
<div class="author_products">
<?php if ( $loop->have_posts() ) { ?>
<ul class="author_pubproducts">
<?php while ( $loop->have_posts() ) : $loop->the_post();
woocommerce_get_template_part( 'content', 'product' );
endwhile; ?>
</ul>
<?php
} else {
echo __( 'No products found', 'textdomain' );
}
wp_reset_postdata();
?>
希望能成功
- 2 回答
- 0 關(guān)注
- 143 瀏覽
添加回答
舉報(bào)