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


Custom comment field, not to display on reply

  • 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.

  • @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');
Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Custom comment field, not to display on reply’ is closed to new replies.