0

Here's the code in question. It started looking like this:

$comments_by_type = &separate_comments(get_comments('status=approve&post_id=' . $id));  
return count($comments_by_type['comment']);

I removed the & signs per other posts I have seen but it didn't help.

$comments_by_type = separate_comments(get_comments('status=approve post_id=' . $id));
return count($comments_by_type['comment']);
  • the arguments for separate_comments are being passed by-reference as function separate_comments(&$comments). You would need to assign get_comments to a variable. $comments = get_comments('status=approve&post_id=' . $id); Then separate_comments($comments); – fyrye Nov 1 '18 at 17:25
  • I tried your suggestion: $comments_by_type = (get_comments('status=approve&post_id=' . $id)); separate_comments($comments); return count($comments_by_type['comment']); it didn't work.....thanks for trying. – MBenson Nov 1 '18 at 18:51
  • You passed the wrong variable name to separate_comments as you never defined $comments, please see my answer. – fyrye Nov 1 '18 at 19:11
1

The issue is caused by the arguments for separate_comments being passed by-reference. Source: function separate_comments(&$comments). This means passing a function as an argument is restricted.

To resolve the issue you need to assign the get_comments function results to a variable.

$comments = get_comments('status=approve&post_id=' . $id);
$comments_by_type = separate_comments($comments);
return count($comments_by_type['comment']);

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.