it’s been a while since I used wordpress and I am trying to us e advanced custom fields, I am trying to output the post ID inside a loop on a page, so i can use get_field to output the post contents. Ths $post->ID gives me the page id not the post id so thr wrong number is being outputted, how do I get the post ID?
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php $current_id = $post->ID ?>
<?php echo $current_id ?>
<h1><?php the_field('titleFart', $current_id); ?></h1>
<?php endwhile; // end of the loop. ?>
<?php endif; ?>
3 Answers
Dont use query_posts
or WP_Query
if you need it in the main loop. Dont ever use query_posts
anyway.
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php $current_id = get_the_ID(); ?>
<?php echo $current_id ?>
<h1><?php the_field('titleFart', $current_id); ?></h1>
<?php endwhile; // end of the loop. ?>
<?php endif; ?>
Because: get_the_ID()