2 回答

TA贡献1790条经验 获得超9个赞
您可以使用未记录的参数“author”在 WC_Query 中简单地按作者 ID 获取产品,如下所示:
$products = wc_get_products( array(
'status' => 'publish',
'limit' => -1,
'author' => get_current_user_id()
) );
你将得到一个WC_Product对象数组

TA贡献1797条经验 获得超6个赞
您可以像这样使用自定义查询
<?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 关注
- 114 浏览
添加回答
举报