I’m trying to show custom posts that contain a meta variable that matches a comment ID. I am using the following code whereby i need to pull in the comment ID dynamically:
<?php
$args = array( 'post_type' => 'paidbriefs', 'meta_key' => 'Comment_ID', 'meta_value' => **CURRENT COMMEND ID TO GO HERE** , 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
echo 'paid';
endwhile; wp_reset_query(); ?>
I have tried using
<?php comment_ID();?>
to get the comment ID but this does not work. The code works if I input the numeric comment id but I cant get it to work with by pulling the id in dynamically. Can anyone help with how to do this, it’s driving me mad!?
prints/echoes the ID directly, so
might be what you are looking for.
It’s a common gotcha with the WordPress helper functions, to confuse those which echo a variable directly with those returning values 🙂