I needed to use new WP_Comment_Query
and set my $args
to show only this post, with the meta attached. Hope this helps someone!
<?php
comment_form();
if (have_comments()) : ?>
<div class="container">
<div class="btn-group flex">
<button type="button" onclick="window.location.href="https://wordpress.stackexchange.com/questions/406158/<?php echo the_permalink();?>/?cmeta=ALL"">SHOW ALL</button>
<button type="button" onclick="window.location.href="<?php echo the_permalink();?>/?cmeta=BUY"">BUY</button>
<button type="button" onclick="window.location.href="<?php echo the_permalink();?>/?cmeta=SELL"">SELL</button>
<button type="button" onclick="window.location.href="<?php echo the_permalink();?>/?cmeta=TRADE"">TRADE</button>
<button type="button" onclick="window.location.href="<?php echo the_permalink();?>/?cmeta=TALK"">TALK</button>
</div>
</div>
<?php
if(isset($_GET['cmeta'])){
$commentmeta=$_GET['cmeta'];
$wantto= get_comment_meta( $comment_id, 'wantto', true );
$args = array(
'post_id' => get_the_ID(),
'meta_query' => array(
array(
'key' => 'wantto',
'value' => $commentmeta,
),
)
);
$comment_query = new WP_Comment_Query( $args );
$comments = $comment_query->comments;
echo '<ol class="post-comments">';
wp_list_comments(array(
'style' => 'ol',
'short_ping' => true,
));
echo $wantto;
echo '</ol>';
/* much simpler one to style probably
if ( $comments ) {
foreach ( $comments as $comment ) {
echo '<p>' . $comment->comment_content . '</p>';
}
} else {
echo 'No comments found.';
}
*/
}else{
$wantto= get_comment_meta( $comment_id, 'wantto', true );
echo '<ol class="post-comments">';
wp_list_comments(array(
'style' => 'ol',
'short_ping' => true,
));
echo $wantto;
echo '</ol>';
}
endif;
$comment_id=get_comment_ID();
echo $wantto;
?>