# Excluding posts used for carousel slider from the Latest Post section on blog page

**URL:** <https://forum.pinegrow.com/t/excluding-posts-used-for-carousel-slider-from-the-latest-post-section-on-blog-page/286>\
**Category:** Pinegrow WP\
**Created:** [October 19, 2016, 3:43pm UTC](https://forum.pinegrow.com/t/excluding-posts-used-for-carousel-slider-from-the-latest-post-section-on-blog-page/286 "2016-10-19T15:43:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jan](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@Jan](https://forum.pinegrow.com/u/Jan)\
**Post date:** [October 19, 2016, 3:43pm UTC](https://forum.pinegrow.com/t/excluding-posts-used-for-carousel-slider-from-the-latest-post-section-on-blog-page/286/1 "2016-10-19T15:43:31Z")

</div>

So, I’ve adapted Bootstraps Carousel within Pinegrow to show full screen and to always focus on the center of the image. Using the same rules as Pinegrow has set up in the carousel/slider component I display these on my front-page.php (it’s a website with a blog.) So, to make that work you create a post, upload a featured image and select “Home-Slider” category, now these will all show in the carousel.

The issue I’m having is on my ‘Latest Posts’ page (index.php.) There’s obviously no point those posts showing up there but I don’t know how to prevent it. I’ve found a [helpful article](https://codex.wordpress.org/Function_Reference/wp_get_recent_posts#Examples) on Wordpress that pretty much gives the answer but, I’ve no idea how to implement it in my contents-page.php. Implement it properly at least. Nothing i do with it makes a difference.

```
<h2>Recent Posts</h2>
<ul>
<?php
	$args = array( 'numberposts' => '5', 'tax_query' => array(
			array(
				'taxonomy' => 'post_format',
				'field' => 'slug',
				'terms' => 'post-format-aside',
				'operator' => 'NOT IN'
			), 
			array(
				'taxonomy' => 'post_format',
				'field' => 'slug',
				'terms' => 'post-format-image',
 				'operator' => 'NOT IN'
			)
	) );
	$recent_posts = wp_get_recent_posts( $args );
	foreach( $recent_posts as $recent ){
		echo '<li><a href="' . get_permalink($recent["ID"]) . '">' . ( __($recent["post_title"])).'</a> </li> ';
	}
	wp_reset_query();
?>
</ul>

```

So, if anyone with some more Wordpress ‘savvy’ can advise, it would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![Jan](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@Jan](https://forum.pinegrow.com/u/Jan)\
**Post date:** [October 20, 2016, 12:36pm UTC](https://forum.pinegrow.com/t/excluding-posts-used-for-carousel-slider-from-the-latest-post-section-on-blog-page/286/2 "2016-10-20T12:36:52Z")

</div>

**Update**  
I found [This Useful Answer](http://forum.pinegrow.com/t/remove-a-category-in-a-loop-wp-theme/192) from @Emmanuel on another post, which should make it work. However, after finding the post(s) ID (1018 to choose just one,) entering it into the Category section of Category Parameters and choosing ‘Not In’ from the Category Opts, the unwanted post(s) still show.

 ![](https://canada1.discourse-cdn.com/flex036/uploads/pinegrow/original/1X/6a6dfa9eb78d8bde1f6ffbe733d69f6db78fca11.png)

I’m unsure whether this should make any difference to ‘content-home.php,’ but it hasn’t. It has however added the relevant code to my ‘index.php.’

```
    <code> <?php
                        $cat_filter_args = array(
                            'category__not_in' => '1018'
                        )
                    ?>
                    <?php $cat_filter = new WP_Query( $cat_filter_args ); ?>
                    <?php if ( $cat_filter->have_posts() ) : ?>
                        <?php while ( $cat_filter->have_posts() ) : $cat_filter->the_post(); ?></code>

```

So, it really should be working. Again, any advice would be gratefully received.

---

<div class="post-metadata">

**Author:** ![Jan](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@Jan](https://forum.pinegrow.com/u/Jan)\
**Post date:** [October 22, 2016, 12:11am UTC](https://forum.pinegrow.com/t/excluding-posts-used-for-carousel-slider-from-the-latest-post-section-on-blog-page/286/3 "2016-10-22T00:11:56Z")

</div>

**Update: Fixed**

After pulling my hair out for three days or so I’ve finally fixed it. I was going about it all wrong. Perhaps by ‘speed-reading’ other peoples solutions, I don’t know but, It’s all sorted now.

What I should have been doing was excluding specific **Posts** by _ID_ as opposed to excluding **Categories** by _ID_.

I eventually found this code worked:

```
function exclude_single_posts_home($query) {
      if ($query->is_home() && $query->is_main_query()) {
        $query->set('post__not_in', array(7,11));
      }
    }

    add_action('pre_get_posts', 'exclude_single_posts_home');

```

It did break the site a couple of times, but I’m a happy camper now, so I’ll give myself a pat on the back.  
Solution source can be found [Here](https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts#Exclude_Single_Posts_by_I.D_From_Home_Page).
