Title: get_comment_id_fields
Published: April 25, 2014
Last modified: August 20, 2026

---

# get_comment_id_fields( int|WP_Post|null $post = `null` ): string

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/get_comment_id_fields/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_comment_id_fields/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_comment_id_fields/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/get_comment_id_fields/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/get_comment_id_fields/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_comment_id_fields/?output_format=md#changelog)

Retrieves hidden input HTML for replying to comments.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_comment_id_fields/?output_format=md#parameters)󠁿

 `$post`int|[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)
|nulloptional

The post the comment is being displayed for.
 Defaults to the current global post.

Default:`null`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_comment_id_fields/?output_format=md#return)󠁿

 string Hidden input HTML for replying to comments.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_comment_id_fields/?output_format=md#source)󠁿

    ```php
    function get_comment_id_fields( $post = null ) {
    	$post = get_post( $post );
    	if ( ! $post ) {
    		return '';
    	}

    	$post_id     = $post->ID;
    	$reply_to_id = _get_comment_reply_id( $post_id );

    	$comment_id_fields  = "<input type='hidden' name='comment_post_ID' value='$post_id' id='comment_post_ID' />\n";
    	$comment_id_fields .= "<input type='hidden' name='comment_parent' id='comment_parent' value='$reply_to_id' />\n";

    	/**
    	 * Filters the returned comment ID fields.
    	 *
    	 * @since 3.0.0
    	 *
    	 * @param string $comment_id_fields The HTML-formatted hidden ID field comment elements.
    	 * @param int    $post_id           The post ID.
    	 * @param int    $reply_to_id       The ID of the comment being replied to.
    	 */
    	return apply_filters( 'comment_id_fields', $comment_id_fields, $post_id, $reply_to_id );
    }
    ```

[View all references](https://developer.wordpress.org/reference/file/wp-includes/comment-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/comment-template.php#L2046)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/comment-template.php#L2046-L2068)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/get_comment_id_fields/?output_format=md#hooks)󠁿

 [apply_filters( ‘comment_id_fields’, string $comment_id_fields, int $post_id, int $reply_to_id )](https://developer.wordpress.org/reference/hooks/comment_id_fields/)

Filters the returned comment ID fields.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_comment_id_fields/?output_format=md#related)󠁿

| Uses | Description | 
| [_get_comment_reply_id()](https://developer.wordpress.org/reference/functions/_get_comment_reply_id/)`wp-includes/comment-template.php` |

Gets the comment’s reply to ID from the $_GET[‘replytocom’].

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [get_post()](https://developer.wordpress.org/reference/functions/get_post/)`wp-includes/post.php` |

Retrieves post data given a post ID or post object.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/get_comment_id_fields/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_comment_id_fields/?output_format=md#)

| Used by | Description | 
| [comment_id_fields()](https://developer.wordpress.org/reference/functions/comment_id_fields/)`wp-includes/comment-template.php` |

Outputs hidden input HTML for replying to comments.

  | 
| [comment_form()](https://developer.wordpress.org/reference/functions/comment_form/)`wp-includes/comment-template.php` |

Outputs a complete commenting form for use within a template.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_comment_id_fields/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.2.0](https://developer.wordpress.org/reference/since/6.2.0/) | Renamed `$post_id` to `$post` and added [WP_Post](https://developer.wordpress.org/reference/classes/wp_post/) support. | 
| [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fsummer-heart-0930.chufeiyun1688.workers.dev%3A443%2Fhttps%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_comment_id_fields%2F)
before being able to contribute a note or feedback.