Title: Exclude posts by ID
Last modified: August 20, 2016

---

# Exclude posts by ID

 *  Resolved [czcsabi](https://wordpress.org/support/users/czcsabi/)
 * (@czcsabi)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/exclude-posts-by-id/)
 * Hi,
 * A nice addition would be if one could specify to exclude some posts/pages by 
   ID. This would improve the functionality of the plugin even more making it a 
   one-stop-shop for post widgets.
    The Random Post for Widget plugin already has
   it:
 *     ```
       function form($instance)
         {
           $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
           $title = $instance['title'];
       	$noofpost = $instance['noofpost'];
       	$hidepost = $instance['hidepost'];
       ?>
         <p>
         <label for="<?php echo $this->get_field_id('title'); ?>">Title: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label>
         <label for="<?php echo $this->get_field_id('noofpost'); ?>">No. of Post: <input class="widefat" id="<?php echo $this->get_field_id('noofpost'); ?>" name="<?php echo $this->get_field_name('noofpost'); ?>" type="text" value="<?php echo attribute_escape($noofpost); ?>" /></label>
         <label for="<?php echo $this->get_field_id('hidepost'); ?>">Exclude Posts by ID(comma seperated): <input class="widefat" id="<?php echo $this->get_field_id('hidepost'); ?>" name="<?php echo $this->get_field_name('hidepost'); ?>" type="text" value="<?php echo attribute_escape($hidepost); ?>" /></label>
         </p>
       <?php
         }
   
         function update($new_instance, $old_instance)
         {
           $instance = $old_instance;
           $instance['title'] = $new_instance['title'];
       	$instance['noofpost'] = $new_instance['noofpost'];
       	$instance['hidepost'] = $new_instance['hidepost'];
           return $instance;
         }
   
         function widget($args, $instance)
         {
           extract($args, EXTR_SKIP);
   
           echo $before_widget;
           $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
       	$noofpost = $instance['noofpost'];
       	$hidepost = $instance['hidepost'];
   
           if (!empty($title))
             echo $before_title . $title . $after_title;
       	if (!empty($noofpost))
       		{
       	  		$noofpost;
       	  	}
       	else
       		{
       	 		$noofpost=5;
       	  	}
           // WIDGET CODE GOES HERE
       	$arr = explode(",",$hidepost);
       	$args = array(
       	'post__not_in' => $arr,
       	'post_type' => 'post',
       	'posts_per_page' => $noofpost,
       	'orderby' => rand
       	);
       	query_posts( $args );
       	if (have_posts()) :
       		echo "<ul>";
       		while (have_posts()) : the_post();
       			echo "<li><a href='".get_permalink()."'>".get_the_title();
       			echo "</a></li>";	
   
       		endwhile;
       		echo "</ul>";
       	endif;
       	wp_reset_query();
   
           echo $after_widget;
       ```
   
 * Best Regards,
    Csaba
 * [http://wordpress.org/extend/plugins/flexible-posts-widget/](http://wordpress.org/extend/plugins/flexible-posts-widget/)

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

 *  Plugin Author [DaveE](https://wordpress.org/support/users/dpe415/)
 * (@dpe415)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/exclude-posts-by-id/#post-3400581)
 * Hi Csaba,
 * Thanks for the suggestion. I’ll add it to the feature request queue. For now,
   you could accomplish the same thing by using a special category, tag or other
   taxonomy & term and only map the posts/pages you want to that term. Then, get
   posts from that term with FPW.
 * Cheers!
 *  Thread Starter [czcsabi](https://wordpress.org/support/users/czcsabi/)
 * (@czcsabi)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/exclude-posts-by-id/#post-3400592)
 * Hi Dave,
 * thank you for your reply and suggestion for a workaround.
 * Best Regards.

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

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

 * ![](https://ps.w.org/flexible-posts-widget/assets/icon-256x256.jpg?rev=984592)
 * [Flexible Posts Widget](https://wordpress.org/plugins/flexible-posts-widget/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/flexible-posts-widget/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/flexible-posts-widget/)
 * [Active Topics](https://wordpress.org/support/plugin/flexible-posts-widget/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/flexible-posts-widget/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/flexible-posts-widget/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [czcsabi](https://wordpress.org/support/users/czcsabi/)
 * Last activity: [13 years, 4 months ago](https://wordpress.org/support/topic/exclude-posts-by-id/#post-3400592)
 * Status: resolved