i am using this code:

$args = array(
    'user_id' => get_current_user_id(),
$comment = get_comments( $args ); 


i dont know what is wrong with it.

user is logged in but the array is empty. whats wrong ?



  • fixed! i was using ajax to insert comments. forgot to add 'user_id' for wp_insert_comment function. – RadioTunes.in Aug 22 '17 at 9:44

You could try this way:

$my_user = get_current_user_id();
$args = array(
    'post_type' => 'custom-post-type',
    'user_id' => $my_user,

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


Provided that your user has comments!!

  • thanks. but that is not working either. the returned $comments is empty! – RadioTunes.in Aug 22 '17 at 8:50
  • i am using this code in a page with custom page template if this helps. – RadioTunes.in Aug 22 '17 at 8:50
  • without more details on the page, I cannot see other problems than catching the user_id before the args array. – Fabio Marzocca Aug 22 '17 at 8:55
  • and also i am sure that the user passed to get_comments has two comments in custom_post_type. – RadioTunes.in Aug 22 '17 at 8:55
  • Ahh, you didn't say that it was a CPT. I have edited my code. – Fabio Marzocca Aug 22 '17 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.