Omit single post from the loop using pre_get_posts ? (1 post)

  1. crazywhistlepig
    Posted 8 years ago #

    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) {
    return $query;

    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))
    	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!

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 8 years ago by crazywhistlepig
  • This topic is not resolved
  • WordPress version: 2.3.3