Solved

Wordpress display specific posts on a page

Posted on 2014-04-17
2
470 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Query still returning duplicates 5 27
Showing random records from database 10 36
Wordpress DB connection error 4 13
CSS: Making Pure CSS read more boxes thinner 5 30
Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…
The viewer will learn how to count occurrences of each item in an array.

786 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