1

I am trying to get the comment ID in the custom callback function that I can use in wp-list_comments. Any help on how to do this? Thanks in advance

I am using wp_list_comments as: wp_list_comments('avatar_size=60&type=comment&callback=get_the_rating');

Note: I was trying to use arguments earlier but I am not sure if I can use arguments in callback functions.

0

The callback is already passed arguments but crazily the codex doesn't document them. However it does give you an example and the first two lines are:

function mytheme_comment($comment, $args, $depth) {
    $GLOBALS['comment'] = $comment;

which matches the equivalent functions in the bundled styles. Once you've set the comment object passed as the global as in that example then you're then free to use get_comment_ID() as usual.

If you didn't want to set the global then

$my_comment_ID = apply_filters( 'get_comment_ID', $comment->comment_ID );

is equivalent, but it's probably safer to go through get_comment_ID().

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.