This is not working and also I don’t know how can I get the comments
of the current user.
You have already used the current user’s ID in your code…
echo 'User ID: ' . $current_user->ID;
… but you hard-code a single ID in the get_comments
argument array. Don’t do that. Use the current user ID.
$args = array(
'user_id' => $current_user->ID, // use user_id
'post_type' => 'my-CPT',
);
I am uncertain of the relationship between your user comments and wp_list_comments
. You have already output the user comments so I don’t why you are running wp_list_comments
unless you are trying to output a different set of comment or you are trying to output the same comments again (which is weird). Either way, you need to pass wp_list_comments
a set of comments as in this example from the Codex (re-formatted to be less confusing):
//Gather comments for a specific page/post
$comments = get_comments(
array(
'post_id' => XXX,
'status' => 'approve' //Change this to the type of comments to be displayed
)
);
//Display the list of comments
wp_list_comments(
array(
'per_page' => 10, //Allow comment pagination
'reverse_top_level' => false //Show the latest comments at the top of the list
),
$comments
);
Note the second argument $comments
, which is the output of a call to get_comments
. The context you seem to be using this in makes me think that that is going to be required.