Custom comment type wordpress

When i insert a comment i use the following code

$data = array(
    'comment_post_ID' => $postid,
    'comment_content' => 'User Review',
    'comment_type' => 'review',
    'user_id' => $userid,
    'comment_date' => $time,
    'comment_approved' => 1,
);

$commentid  = wp_insert_comment($data);

If i try to get these comments based on "comment_type", I am not getting results

    $args = array(

    'user_id' => $userid,
    'post_type' => 'review'     
);
$comments = get_comments($args);

get_comments can't be used for getting comments of particular type?

How to get comments of type review?

Answers


Try this code, I hope this will help.

$args = array(

    'user_id' => $userid,
    'type' => 'review'     
);
$comments = get_comments($args);

You can write a custom query to get comments of type review.

<?php
global $wpdb;
$query = "SELECT * 
        FROM $wpdb->comments 
        WHERE $wpdb->comments.user_id =$userid AND $wpdb->comments.comment_type = 'review'";
$results = $wpdb->get_results($query);
print_r($results);
?>

Later, you can just loop through the results to print them. And if you want comments on particular post then add a condition in WHERE clause, AND comment_post_ID = $post_id.


Need Your Help

Android Webview - Webpage should fit the device screen

android webview scaling android-webview

I have tried the following to fit the webpage based on the device screen size.

Prevent comment conflicts in strings.resx (Visual Studio 2010)

visual-studio-2010 resources versioning conflict

Suppose an international team of developers, using various flavors of Visual Studio 2010 (understand: in different languages), and working on a versioned project.