0

So I want to add a comment redirect code to my comment form. I know I have this part right here:

<input name="redirect_to" type="hidden" value="http://domain.com/thank-you" />

So what I want to do is wrap that in an if-else to see if it's their first comment:

if ( $FirstTimeComment = true ) : ?>
    <input name="redirect_to" type="hidden" value="http://domain.com/thank-you" />
<?php endif;

I'm just not sure how to form the if-else to check if they are a first time commentator or not.

Suggestions?

1 Answer 1

0

Since the comment form is generated before the comment is submitted that won't work too well logically.

The better option is comment_post_redirect filter:

/**
 * Filter the location URI to send the commenter after posting.
 *
 * @since 2.0.5
 *
 * @param string $location The 'redirect_to' URI sent via $_POST.
 * @param object $comment  Comment object.
 */
$location = apply_filters( 'comment_post_redirect', $location, $comment );

You can hook into it, check how many comments user has, and change the URL in $location as necessary.

2
  • That's perfect, thank you, but how do I check how many comments the user has (my initial question)? Commented Oct 20, 2014 at 13:32
  • The $comment passed should have all its data, you can fetch something like user's email out of it and use get_comments() to query how many are associated with it. Hadn't tried in code, just talking from the top of my head. :)
    – Rarst
    Commented Oct 20, 2014 at 13:35

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.