Title: Excluding a post by ID
Last modified: August 30, 2016

---

# Excluding a post by ID

 *  Resolved [sia77](https://wordpress.org/support/users/sia77/)
 * (@sia77)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/excluding-a-post-by-id/)
 * Hi there,
 * I’m trying to exclude a post by id, so I have added the following code spinet
   to page_posts.php
 *     ```
       if ( isset( $atts['no_ids'] ) ) {
       	$post_no_ids = explode( ',', $atts['no_ids'] );
       	$this->args['post__not_in'] = $post_no_ids;
       	$this->args['posts_per_page'] = count( $post_no_ids );
       }
       ```
   
 * And I commented out the following, because it seem it was interfering with get
   the excluded id assign to no__in_post
 *     ```
       if ( ! isset( $this->args['ignore_sticky_posts'] ) ) {
       	$this->args['post__not_in'] = get_option( 'sticky_posts' );
       }
   
       if ( ! isset( $this->args['ignore_sticky_posts'] ) ) {
       	$this->args['post__not_in'] = get_option( 'sticky_posts' );
       }
       ```
   
 * Seems to be working partially, because my shortcode is actually is this:
    `[ic_add_posts
   post_type='preamble,service' template='event_service1.php' no_ids='637']`
 * Now, there are two posts of type preamble, and several of type service, but what
   I see is a post of type preamble (the on that is not excluded), and post of type
   service are not listed.
 * I ran the following:
    `echo "<p>REQUEST:$wp_query->request</p>";` but I get this:
   REQUEST:SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND (wp_posts.ID = ‘629’) AND
   wp_posts.post_type = ‘page’ ORDER BY wp_posts.post_date DESC
 * But when I run this:
    `print_r($this->args);`
 * I get the following:
    `Array ( [post_type] => Array ( [0] => preamble [1] => 
   service ) [post_status] => publish [orderby] => date [order] => DESC [paginate]
   => [template] => event_service1.php [posts_per_page] => 1 [no_ids] => 637 [post__not_in]
   => Array ( [0] => 637 ) )`
 * Any ideas?
    Thanks,
 * [https://wordpress.org/plugins/posts-in-page/](https://wordpress.org/plugins/posts-in-page/)

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

 *  Thread Starter [sia77](https://wordpress.org/support/users/sia77/)
 * (@sia77)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/excluding-a-post-by-id/#post-6210977)
 * I figured what my problem was. It’s working now.
 *  Thread Starter [sia77](https://wordpress.org/support/users/sia77/)
 * (@sia77)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/excluding-a-post-by-id/#post-6210978)
 * So basically, add the first code snippet, and set ignore_sticky_posts to true
   in the shortcode, so you don’t have to comment out the second code snippet.
    
   In my case, I had to use two short code to get what I wanted….
 *  Plugin Author [Eric Amundson](https://wordpress.org/support/users/sewmyheadon/)
 * (@sewmyheadon)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/excluding-a-post-by-id/#post-6211110)
 * Thanks sia77!

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

The topic ‘Excluding a post by ID’ is closed to new replies.

 * ![](https://ps.w.org/posts-in-page/assets/icon-256x256.png?rev=1596190)
 * [Posts in Page](https://wordpress.org/plugins/posts-in-page/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/posts-in-page/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/posts-in-page/)
 * [Active Topics](https://wordpress.org/support/plugin/posts-in-page/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/posts-in-page/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/posts-in-page/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Eric Amundson](https://wordpress.org/support/users/sewmyheadon/)
 * Last activity: [10 years, 11 months ago](https://wordpress.org/support/topic/excluding-a-post-by-id/#post-6211110)
 * Status: resolved