0

I am using a custom function to pre fill the comment text area with the number of comment count but getting an error header already sent can any body guide me here's the code I am using

  add_action('pre_comment_on_post', 'dump_comment');
   function dump_comment($post_id, $author=null, $email=null) {
   $comcnt = $cmntcount = comments_number( '#0', '#1', '#%' );
   $comment = ( isset($_POST['comment']) ) ? trim($_POST['comment']) : null;
   if (!$comment) {
   $_POST['comment'] = 'Design' . '$comcnt';

    }
   }

1 Answer 1

0

I think the reason for your header already sent error is that you are using

comments_number()

that will echo the value.

Try instead

get_comments_number( $post_id );

to return it.

The Codex info on this function says that it returns the total number of comments, trackbacks, and pingbacks for the post.

2
  • Works like a charm just want to confirm ? if this exclude the trackback and pings ?
    – Cid Ubaid
    Commented Jun 2, 2013 at 9:39
  • ok great ;-) ps: the Codex says that this will give you the total number of comments, Trackbacks, and Pingbacks for a post
    – birgire
    Commented Jun 2, 2013 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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