I am using the following script to output 3 entries onto my WordPress page.
However, for some reason it only outputs the first entry from that list. I moved the numbers around in the array, and it still only outputs 1 <div>.
Despite there definitely being posts with the ID, 1, 4 & 31.
Any ideas how to fix this?
<?php $thePostIdArray = array("1","4","31"); ?>
<?php $limit = 3; ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); $counter++; ?>
<?php if ( $counter < $limit + 1 ): ?>
<div class="post" id="post-<?php the_ID(); ?>">
<?php $post_id = $thePostIdArray[$counter-1]; ?>
<?php $queried_post = get_post($post_id); ?>
<h2><?php echo $queried_post->post_title; ?></h2>
</div>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
Many thanks for any pointers.
I would do it like this: