?
Solved

Wordpress display specific posts on a page

Posted on 2014-04-17
2
Medium Priority
?
478 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 25

Accepted Solution

by:
James Rodgers earned 2000 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…
The purpose of this video is to demonstrate how to Import and export files in WordPress. 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 : Click on Too…
Suggested Courses

762 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