$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>plugins - Get all woocommerce commentsreviews|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

plugins - Get all woocommerce commentsreviews

matteradmin9PV0评论

What I need to achieve is to get all comments from all products in Woocommerce.

This is not getting me ANY comments at all...

<?php $comments = get_comments( array( 'post_type' => 'product') ); ?>

However

<?php $comments = get_comments( array( 'post_id' => '4169') );

Gets me comments for particular product ID. How to query ALL comments?

Thanks in advance.

What I need to achieve is to get all comments from all products in Woocommerce.

This is not getting me ANY comments at all...

<?php $comments = get_comments( array( 'post_type' => 'product') ); ?>

However

<?php $comments = get_comments( array( 'post_id' => '4169') );

Gets me comments for particular product ID. How to query ALL comments?

Thanks in advance.

Share Improve this question asked Oct 31, 2013 at 10:08 kromakroma 31 gold badge1 silver badge3 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 2

Please try this:

 $args = array( 
                'number'      => 100, 
                'status'      => 'approve', 
                'post_status' => 'publish', 
                'post_type'   => 'product' 
        );

 $comments = get_comments( $args );

where you can edit the number of comments to your needs.

Debug:

Maybe something is changing it via the pre_get_comments hook?

To debug it you can check out the SQL query with:

 global $wpdb;
 printf( '<pre>%s</pre>', $wpdb->last_query );

where you add this directly below the above get_comments() code snippet.

Also check the edit-comments.php screen if the comments show up there and their status.

You'll need to loop through all comments and display them. Something like this will do the trick:

        $args = array( 
            'status'      => 'approve', 
            'post_status' => 'publish', 
            'post_type'   => 'product' 
        );

        $comments = get_comments( $args );

        foreach( $comments as $comment ) :
            echo( $comment->comment_author . '<br />' . $comment >comment_content);
        endforeach; 

You can also pass in the 'number' parameter if you want to specify how many comments to show. Default is null (no limit).

Woocommerce overrides comment queries, which seems to impact WC_Comment_Query and get_comments(), by filtering out shop comments directly in the SQL.

Adding the below before using WC_Comment_Query prevented shop comments from being excluded in my query.

remove_filter('comments_clauses', array( 'WC_Comments' ,'exclude_order_comments'), 10, 1 );

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far