Home Forums General Issues Custom comment field, not to display on reply


Custom comment field, not to display on reply

    • jeffuk

    • April 27, 2020 at 3:06 am

    I added a custom field to comments which work and displays on comments as expected.

    Problem is I don’t want the field to be shown again when a user replies to a comment. Is there a workaround?

  • Are you able to post the code? I’m thinking that you use count and only display the field if the result is equal to one.

    So, if ( user comment count == 1 ) { echo $field }.

  • This will remove the field if the person has already made any comment on the current post.

    add_filter('acf/prepare_field/name=YOUR_FIELS_NAME', 'remove_if_previous_comments');
    function remove_if_previous_comments($field) {
      if (!is_user_logged_in()) {
        return $field;
      global $post;
      $user = get_current_user_id();
      $args = array(
        'author__in' => array($user),
        'post_id' => $post->ID,
        'count' => true
      $count = get_comments($args);
      if ($count) {
        $field = false;
      return $field;

    unfortunately you cannot remove the field depending on if the comment is a reply to another comment or not. WP only has one comment form and it’s just moved around when replying to other comments.

    • jeffuk

    • May 13, 2020 at 11:14 pm

    Thanks John.

    • Luca_R

    • October 12, 2020 at 11:48 am

    @hube2 thank you!
    I have a similar case: I have a set of nine mandatory fields in comments, and I need to hide all of them to users who have already posted a comment. So, the following comments from the same users would be only basic text with no custom fields.
    Can I put an array in the first line of code, or the set name, or what?
    Thanks in advance

    // array of field names
    $fields = array(
    foreach ($fields as $field) {
      add_filter('acf/prepare_field/name='.$field, 'remove_if_previous_comments');
    • Luca_R

    • October 13, 2020 at 7:29 am

    @hube2 thank you very much!

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.