Solved

Wordpress display specific posts on a page

Posted on 2014-04-17
2
467 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
ID: 40007878
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
ID: 40007980
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses four methods for overlaying images in a container on a web page
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…

914 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

20 Experts available now in Live!

Get 1:1 Help Now