I have a loop (the_loop) to echo featured images on my slider but I need to filter it to specific post ID only. But get_the_ID is not working.
Here's my code
<?$valid_post_id('1','2','3','4');?>
<?php while( have_posts() ) : the_post(); ?>
<?if(in_array(get_the_ID(),$valid_post_id)):?>
<li class="slide">
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?><?php if( isset( $thumbnail ) ) : ?> style="background:url(<?php echo $thumbnail[0]; ?>) center no-repeat"<?php endif; ?>>
<div class="opacity"></div>
<a class="overlay" href="<?php the_permalink(); ?>" rel="bookmark"></a>
<div class="entry-container">
<h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<div class="entry-summary">
<?php the_excerpt(); ?>
<div class="clear"></div>
</div><!-- .entry-summary -->
</div><!-- .entry-container -->
</div><!-- .post -->
</li>
<?endif;?>
<?php endwhile; ?>
pre_get_posts
filter to include only the IDs you want, rather than querying more posts than you need just to ignore those that don't match values in the array. First person to provide an example gets my vote.