Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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';

    }
   }
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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.

share|improve this answer
    
Works like a charm just want to confirm ? if this exclude the trackback and pings ? –  Cid Ubaid Jun 2 '13 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 Jun 2 '13 at 9:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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