Title: get_posts exclude some posts
Last modified: August 20, 2016

---

# get_posts exclude some posts

 *  [tiaanswart](https://wordpress.org/support/users/tiaanswart/)
 * (@tiaanswart)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/get_posts-exclude-some-posts/)
 * Hello
 * I have the following code in a slider template of mine called slider.php:
 *     ```
       <?php
   
                   $myCategories[] = get_term_by('name', 'Featured', 'category');
   
                   $args = array(
                   'numberposts'     => 5,
                   'offset'          => 0,
                   'category'        => $myCategories[0]->term_id,
                   'orderby'         => 'post_date',
                   'order'           => 'DESC',
                   'post_type'       => 'post',
                   'post_status'     => 'publish',
                   'suppress_filters' => true );
   
                   $myposts = get_posts( $args );
   
                   foreach( $myposts as $post ) :	setup_postdata($post); ?>
   
                       <div data-thumb="<?php $feat_image_small = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'feature-small') ); echo $feat_image_small; ?>">
                           <img src="<?php $feat_image_big = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'feature-big') ); echo $feat_image_big; ?>">
                           <div class="caption elemHover fromRight" style="bottom:65px; padding-bottom:5px; color:#ff0; text-transform:uppercase">
                               <a href="<?php the_permalink(); ?>" style="color:#ff0;"><?php the_title(); ?></a>
                           </div>
                           <div class="caption elemHover fromLeft" style="padding-top:5px;">
                               <?php $little_excerpt = substr(get_the_excerpt(),0,100); $read_more ='<a href="'.get_post_permalink().'" style="color:#ff0;">Read More...</a>'; echo $little_excerpt; echo $read_more; ?>
                           </div>
                       </div>
   
                   <?php endforeach; ?> <?php
               ?>
       ```
   
 * This code works perfectly as I intended for it to work.
 * I call this template file in the header file with get_template_part.
 * Now my issue is this, I want to limit my index.php(home) to only display posts
   that has not already been called by the slider like “Featured” posts.
 * Lets say for arguments sake that I have a “Featured” category and that there 
   are 10 posts in that category.
 * The slider will grab 5 of these posts and display them but the main loop in index.
   php will also include these 5 posts.
 * Don’t get me wrong I don’t want to exclude the entire “Featured” Category only
   the ones that were dynamically displayed in the slider.
 * Any help in this regard will me much appreciated!
 * Thanks a mil!

The topic ‘get_posts exclude some posts’ is closed to new replies.

## Tags

 * [categories](https://wordpress.org/support/topic-tag/categories/)
 * [exclude posts](https://wordpress.org/support/topic-tag/exclude-posts/)
 * [get_posts](https://wordpress.org/support/topic-tag/get_posts/)
 * [get_template_part](https://wordpress.org/support/topic-tag/get_template_part/)
 * [index.php](https://wordpress.org/support/topic-tag/index-php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [tiaanswart](https://wordpress.org/support/users/tiaanswart/)
 * Last activity: [13 years, 9 months ago](https://wordpress.org/support/topic/get_posts-exclude-some-posts/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
