How to get current ID for WP Loop in my case?
I try to loop the GIVEWP (Success), then I try to echo shortcode of GOAL Progress Bar of GiveWP but the problem is, i don't know how to get the current ID.
Here my code:
<?php while ( have_posts() ) : the_post(); ?>
<!-- LOOP -->
<?php echo do_shortcode('[give_goal id="INEEDCURRENTIDHERE" show_text="true" show_bar="true"]'); ?>
<!-- END LOOP -->
<?php endwhile; // end of the loop. ?>
Thank you. :)
How to get current ID for WP Loop in my case?
I try to loop the GIVEWP (Success), then I try to echo shortcode of GOAL Progress Bar of GiveWP but the problem is, i don't know how to get the current ID.
Here my code:
<?php while ( have_posts() ) : the_post(); ?>
<!-- LOOP -->
<?php echo do_shortcode('[give_goal id="INEEDCURRENTIDHERE" show_text="true" show_bar="true"]'); ?>
<!-- END LOOP -->
<?php endwhile; // end of the loop. ?>
Thank you. :)
Share Improve this question edited Dec 26, 2019 at 7:59 Chetan Vaghela 2,4084 gold badges10 silver badges16 bronze badges asked Dec 26, 2019 at 6:58 Syafiq FremanSyafiq Freman 1013 bronze badges 2- 1 Get current id in while loop $id = get_the_id(); then use id in shortcode like do_shortcode('[give_goal id="'.$id.'" show_text="true" show_bar="true"]'); – Chetan Vaghela Commented Dec 26, 2019 at 7:29
- 1 Thanks @ChetanVaghela . It's works! :) – Syafiq Freman Commented Dec 26, 2019 at 8:11
1 Answer
Reset to default 0Try using this:
$post_id = get_the_ID();
OR
global $post;
$post_id = $post->ID;
OR
$post = $wp_query->post;
$post_id = $post->ID;