I am trying to figure out how to echo 4 created fields from a plugin in my theme template for the comment form and customize the comments output as well. The plugin I am using lets me add custom fields to comment_form but I am unable to echo out even one of them in the comments.
The field I am trying to echo in the code below is "$ag_condition". I also tried using the following code in a few variations and couldn't come up with anything that works.
<?php
$args = array(
'orderby' => 'comment_date',
'order' => 'DESC',
'post_type' => 'property',
);
// return a single meta value with the key 'vote' from a defined comment object
$ag_condition = get_comment_meta( $comment->comment_ID, 'agents_condition', true );
$comments = get_comments($args);
foreach($comments as $comment) :
echo('<p>' . $comment->comment_author . '</p><p>' . $comment->comment_content . '</p>');
echo ($ag_condition);
endforeach;
?>
I tried seeking support from the plugin forum and this is the only response I got -
Where $meta['data_name'] is the extra field name you set in our plugin.
echo $comment_meta_key = $meta['data_name'];
$comment_meta_val = get_comment_meta($comment -> comment_ID, $comment_meta_key, true);
My full code --
<?php
$args = array(
'orderby' => 'comment_date',
'order' => 'DESC',
'post_type' => 'property',
);
// return a single meta value with the key 'vote' from a defined comment object
$ag_condition = get_comment_meta( $comment->comment_ID, 'agents_condition', true );
$comments = get_comments($args);
foreach($comments as $comment) :
echo('<div id="' . $comment->comment_ID . '">Agent Name ' . $comment->comment_author . 'Phone' . $comment->comment_phone . 'Reply' . $comment->comment_content . '</div>');
echo ($ag_condition);
endforeach;
?><?php comment_form(); ?>
Im not sure how to correct it, any help is appreciated.
UPDATE
I tried the code and tried this other code I was trying to use to echo a custom field from the users profile (phone number) with their comment replies.
In the comment list I just call on the function.
>
function format_comment() {
> echo '<div class="comment">
> <p>'. ' $comment_author '.'</p>
> <p>'.'get_comment_meta( $comment->comment_ID, "phone", true )'.'</p> </div>' }