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 DESCBut 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,
- The topic ‘Excluding a post by ID’ is closed to new replies.