Solved

Wordpress display specific posts on a page

Posted on 2014-04-17
2
464 Views
Last Modified: 2014-04-17
Hi I am using the follow piece of code display 4 posts on a specific page. But for some reason only the first post id declared in the array is being displayed. So just post id 573 gets posted on the page.

What am I missing?

Thanks

     <div class="thursday">
       <?php $thePostIdArrayT = array('573','537','575','577'); ?>
        <?php $limit = 4 ?>
         <?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 = $thePostIdArrayT[$counter-1]; ?>
         <?php $queried_post = get_post($post_id); ?>
         <h2><?php echo $queried_post->post_title; ?></h2>
		  <?php echo $queried_post->post_content; ?>
         </div>
         <?php endif; ?>
         <?php endwhile; ?>
          <?php endif; ?>
		<a href="/specials/">read more..</a>
     </div>

Open in new window

0
Comment
Question by:niceoneishere
2 Comments
 
LVL 25

Accepted Solution

by:
James Rodgers earned 500 total points
Comment Utility
take a look at this, query the posts directly
<?php
$args=array(
  'posts__in' => array(5,12,2,14,7),
  'post_type' => 'post',
  'post_status' => 'publish',
  'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
  echo 'List of Posts';
  while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    <?php
  endwhile;
}
wp_reset_query();  // Restore global post data stomped by the_post().
?>

Open in new window


from here
http://wordpress.org/support/topic/listing-posts-by-a-pre-filled-array


or using query_posts
put this right above a standard loop

<?php 
query_posts( 'post__in' => array('573','537','575','577') );
 ?>

Open in new window


http://wordpress.org/support/topic/using-a-dynamic-array-with-query_posts-and-post_in
0
 
LVL 1

Author Closing Comment

by:niceoneishere
Comment Utility
Thanks
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now