How can I echo PHP after a comment form submit?

I have tried this but no luck:

$args = array(
    'logged_in_as'         => '',
    'comment_notes_before' => '',
    'comment_notes_after'  => '',
    'name_submit'          => 'thesubmit',
    'id_form'              => 'commentform',
    'id_submit'            => 'submit',
    'title_reply'          => __( "", ET_DOMAIN),
    'title_reply_to'       => __( 'Leave a Reply to %s', ET_DOMAIN),
    'cancel_reply_link'    => __( 'Cancel reply',ET_DOMAIN ),
    'label_submit'         => __( 'continue', ET_DOMAIN ),

comment_form( $args, $post>ID ); 

if ( isset( $_POST['thesubmit'] ) ) {
    update_post_meta( $post->ID, 'buzz', 1 ); 
  • 1
    first, $post->ID instead of $post>ID.
    – Ismail
    Aug 5 '16 at 16:34

Native comment form is not posting to the page itself, but away to a special wp-comment-post.php endpoint.

That endpoint processes the form submission, then redirects back to the page (which rebuilds with submitted comment if necessary). If you want to echo data at the page at the end of this process you would need to somehow keep track of this.

On top of my head you could hook into comment_post_redirect filter and add a GET query with data or something like that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy