Advanced Custom Fields
How to get values from a comment
Documentation Guides How to get values from a comment
To display custom field values within comments, you will need to setup a custom callback function for the
wp_list_comments()function. This is well explained in an article Creating a custom comment list.
All template functions can be used with a comment, however, a second parameter is required to target the specific comment. This is similar to passing through a
$post_idvalue to target a specific post object.
The second parameter can be given in either of 2 formats:
The comment object can be passed as the
$post_idparameter. This is the most simple way to load a value from a comment object. You will be passed a comment object when using a custom callback for the
The comment string can be passed as the
$post_idparameter and is constructed from the comment’s ID. In code, this looks like
Custom fields for comments requires at least ACF version 5
Basic parameter use
This example shows how the second parameter is used to target the specific comment.
Custom comment list
This example shows how to create a custom comment list callback and display some custom fields.
Guides: Get values from another post
On this page
In this category
© 2023 WPEngine, Inc. All rights reserved.