Can you tell me how to display all the products of a certain user (the one who added the product) Woocommerce using a shortcode? I almost managed to create this code, but it gives this error:
Warning: Array to string conversion in /var/www/
What am I doing wrong?
add_shortcode( 'author_products', 'products_current_author' );
function products_current_author() {
$args = [
'author_name' => 'andrey',
'post_type' => 'product',
'posts_per_page' => - 1,
'fields' => 'ids',
];
$ids[] = get_posts( $args );
return do_shortcode( '[products ids="' . join( ",", array_unique( $ids) ) . '"]' );
}
2
Answers
I managed to solve my problem on my own. Here is the working code, tested, working.
According to provided code, to display all products by product author, using woocommerce, the following code can be checked:
It can be checked, if this code works.