Title: Omit single post from the loop using pre_get_posts ?
Last modified: August 19, 2016

---

# Omit single post from the loop using pre_get_posts ?

 *  [crazywhistlepig](https://wordpress.org/support/users/crazywhistlepig/)
 * (@crazywhistlepig)
 * [18 years ago](https://wordpress.org/support/topic/omit-single-post-from-the-loop-using-pre_get_posts/)
 * I’d like to omit posts with the custom field meta “locked=1” from the loop. I
   toyed around with using the pre_get_posts filter based on a similar usage for
   excluding categories such as:
 *     ```
       function myFilter($query) {
       	if ($query->is_feed) {
       		$query->set('cat','-5');
       	}
   
       return $query;
       }
       add_filter('pre_get_posts','myFilter');
       ```
   
 * My goal is to be able to omit from is_feed any posts containing the custom field“
   locked” with any non null value. Without too much knowledge of how filters work
   in WordPress, I tried the code:
 *     ```
       function myFilter($query) {
       	if ($query->is_feed)
       		if (get_post_meta($query->query_vars['page_id'], 'locked', TRUE))
       			$query->set('page_id','-'.$query->query_vars['page_id']);
       	return $query;
       }
       ```
   
 * To no avail. I know I’m probably way off track but just can’t seem to get my 
   head around it tonight. Is this functionality possible or am I dreaming? Is there
   a better way to achieve this? I’m using WP 2.3.3.
 * Thanks in advance!

The topic ‘Omit single post from the loop using pre_get_posts ?’ is closed to new
replies.

## Tags

 * [pre_get_posts](https://wordpress.org/support/topic-tag/pre_get_posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [crazywhistlepig](https://wordpress.org/support/users/crazywhistlepig/)
 * Last activity: [18 years ago](https://wordpress.org/support/topic/omit-single-post-from-the-loop-using-pre_get_posts/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
