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_id value to target a specific post object.
The second parameter can be given in either of 2 formats:
Comment Object
The comment object can be passed as the $post_id parameter. 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 wp_list_comments() function.
Comment String
The comment string can be passed as the $post_id parameter and is constructed from the comment’s ID. In code, this looks like "comment_{$comment->comment_ID}"
Requirements
Custom fields for comments requires at least ACF version 5
Examples
Basic parameter use
This example shows how the second parameter is used to target the specific comment.
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.
Advanced Custom Fields
How to get values from a comment
Documentation Guides How to get values from a comment
Overview
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_id
value to target a specific post object.The second parameter can be given in either of 2 formats:
Comment Object
The comment object can be passed as the
$post_id
parameter. 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 thewp_list_comments()
function.Comment String
The comment string can be passed as the
$post_id
parameter and is constructed from the comment’s ID. In code, this looks like"comment_{$comment->comment_ID}"
Requirements
Custom fields for comments requires at least ACF version 5
Examples
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.
single.php
comments.php
functions.php
Related-
Basic: get_field()
-
Guides: Get values from another post
On this page
In this category
Sign up for the latest Advanced Custom Fields news, updates, and developer tutorials
About
Help
Community
Products
© 2024 WPEngine, Inc. All rights reserved.
1WP Engine is a proud member and supporter of the community of WordPress® users. The WordPress® trademark is the intellectual property of the WordPress Foundation, and the Woo® and WooCommerce® trademarks are the intellectual property of WooCommerce, Inc. Uses of the WordPress®, Woo®, and WooCommerce® names in this website are for identification purposes only and do not imply an endorsement by WordPress Foundation or WooCommerce, Inc. WP Engine is not endorsed or owned by, or affiliated with, the WordPress Foundation or WooCommerce, Inc.
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.