Title: display multiple posts by ID
Last modified: August 19, 2016

---

# display multiple posts by ID

 *  [mk1rs2000](https://wordpress.org/support/users/mk1rs2000/)
 * (@mk1rs2000)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/display-multiple-posts-by-id/)
 * Hi, i need a bit of help, im trying to show multiple posts on my homepage by 
   post id, when i try to ask it for multiple posts it will only show 1, however,
   whe i ask it to show multiple posts by tag id it will show them
 * heres what ive got
 *     ```
       <?php
   
       		$count = 0;
   
       		$duplicated = array();
   
       		$cats = get_categories();
   
       		foreach ($cats as $cat) {
   
       		$the_query = new WP_Query('showposts=3&posts_per_page-1&p=43,41).'.$post->cat_id);
   
       		while ($the_query->have_posts()) : $the_query->the_post(); $do_not_duplicate = $post->ID;
   
       	?>
       ```
   
 * is this possible to do in WP or will i have to just show them by tag id, i want
   to be able to control what is shown on the homepage.
 * probably a simple answer but ive been looking at it for so long i think ive driven
   myself insane

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/display-multiple-posts-by-id/#post-1953416)
 * You have an error in this statement:
 *     ```
       $the_query = new WP_Query('showposts=3&posts_per_page-1&p=43,41).'.$post->cat_id);
       ```
   
 * I am not sure what you are trying to do, but the part after 43,41 is not formed
   correctly. Try setting up your query string as a variable and echo it out to 
   see the problem:
 *     ```
       $q_string = 'showposts=3&posts_per_page-1&p=43,41).'.$post->cat_id;
       echo "<p>The query: $q_string</p>";
       $the_query = new WP_Query($q_string);
       ```
   
 *  Thread Starter [mk1rs2000](https://wordpress.org/support/users/mk1rs2000/)
 * (@mk1rs2000)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/display-multiple-posts-by-id/#post-1953434)
 * hi vtxyzzy, thanks for the post, tried that & stilll cant get it to work, even
   when i edit the code i can still only show 1 post, heres the entire page
 *     ```
       <?php get_header(); ?>
   
       		<div class="col1_home">
   
       			<div class="col1_home_box">
   
       				<?php include(TEMPLATEPATH . '/includes/featured.php'); ?>
   
                </div><!--/col1_home_box-->
   
                <div class="col1_home_box">
   
       		<?php
   
                   if (get_option('woo_layout') == "true") 
   
                       include('layouts/blog.php');			
   
                   else
   
                       include('layouts/default.php');								
   
               ?>
   
                 </div><!--/col1_home_box-->
   
                 <?php
   
       				// Display Video
   
       				include(TEMPLATEPATH . '/includes/video.php'); 
   
       			?>
   
       		</div><!--/col1_home-->
   
               <div class="col_mid_home">
   
               	<div class="mid_box">
   
       	<?php
   
       		$count = 0;
   
       		$duplicated = array();
   
       		$cats = get_categories();
   
       		foreach ($cats as $cat) {
   
       		$the_query = new WP_Query('showposts=3&posts_per_page-1&p=43,41).'.$post->cat_id);
   
       		while ($the_query->have_posts()) : $the_query->the_post(); $do_not_duplicate = $post->ID;
   
       	?>	
   
       				<?php
   
       						$show = true;
   
       						foreach ( $duplicated as $test) { if ( $test == $post->ID) { $show = false; } }
   
       						$count++;
   
       						$duplicated[$count] = $post->ID;
   
       						if ($show) {
   
       				?>
   
       				<div class="post-alt blog">	
   
                      <p class="category"><span><?php echo $cat->cat_name; ?></span></p>
   
       					<h2><a title="<?php _e('Permanent link to ',woothemes); ?> <?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
   
       					<p class="posted_on"><?php _e('Published on',woothemes); ?> <?php the_time('d F Y'); ?> <?php edit_post_link(__('Edit'), ' · ', ''); ?></p>
   
       					<div class="entry">
   
       						<?php the_excerpt(); ?>
   
       					</div>
   
       				</div><!--/post-->
   
       				<?php } ?>
   
       	<?php endwhile; ?>
   
       	<?php } ?>
   
               </div>
   
       		</div>
   
       <?php get_sidebar(); ?>
   
       <?php get_footer(); ?>
       ```
   
 * p=41,43 relates to 2 of the posts that id like to display.
 * thanks so much for the help.
 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/display-multiple-posts-by-id/#post-1953442)
 * OK, I will try again. The line below is not correct, and I do not understand 
   what you are trying to do.
 * `$the_query = new WP_Query('showposts=3&posts_per_page-1&p=43,41).'.$post->cat_id);`
 * I don’t understand what `$post->cat_id` is used for. It cannot be appended to
   the rest of the query string like that.
 * Please try this. Assume that post 54 is one you want to show along with 43 and
   41. Then, code the query like this:
 * `$the_query = new WP_Query('showposts=3&posts_per_page-1&p=43,41,54);`
 * Replace the 54 with your post ID and it should retrieve 3 posts.
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/display-multiple-posts-by-id/#post-1953459)
 * `posts_per_page-1`
 * should read
 * `posts_per_page=-1`
 * and what is the point of having ‘showposts’ and ‘posts_per_page’ in the same 
   query?
 * also:
 * > Multiple Posts/Pages Handling
   > Display only the specify posts:
   > `$query = new WP_Query( array( 'post__in' => array( 2, 5, 12, 14, 20 ) ) );`
 * [http://codex.wordpress.org/Function_Reference/WP_Query#Post_.26_Page_Parameters](http://codex.wordpress.org/Function_Reference/WP_Query#Post_.26_Page_Parameters)

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘display multiple posts by ID’ is closed to new replies.

## Tags

 * [$post->id](https://wordpress.org/support/topic-tag/post-id/)
 * [multiple posts](https://wordpress.org/support/topic-tag/multiple-posts/)
 * [posts](https://wordpress.org/support/topic-tag/posts/)
 * [wp-query](https://wordpress.org/support/topic-tag/wp-query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [Michael](https://wordpress.org/support/users/alchymyth/)
 * Last activity: [15 years, 3 months ago](https://wordpress.org/support/topic/display-multiple-posts-by-id/#post-1953459)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
