<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Intercepting the WordPress Loop with Pre_get_posts</title>
	<atom:link href="http://seanbehan.com/programming/intercepting-the-wordpress-loop/feed/" rel="self" type="application/rss+xml" />
	<link>http://seanbehan.com/programming/intercepting-the-wordpress-loop/</link>
	<description>Web Programming, Ruby on Rails, Wordpress, PHP from Burlington, Vermont</description>
	<lastBuildDate>Wed, 16 May 2012 14:49:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: bseanvt</title>
		<link>http://seanbehan.com/programming/intercepting-the-wordpress-loop/#comment-1579</link>
		<dc:creator>bseanvt</dc:creator>
		<pubDate>Fri, 07 Oct 2011 17:48:32 +0000</pubDate>
		<guid isPermaLink="false">http://seanbehan.com/?p=968#comment-1579</guid>
		<description>thank you for the clarification!</description>
		<content:encoded><![CDATA[<p>thank you for the clarification!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ian Dunn</title>
		<link>http://seanbehan.com/programming/intercepting-the-wordpress-loop/#comment-1578</link>
		<dc:creator>Ian Dunn</dc:creator>
		<pubDate>Fri, 07 Oct 2011 17:38:47 +0000</pubDate>
		<guid isPermaLink="false">http://seanbehan.com/?p=968#comment-1578</guid>
		<description>Just a minor correction: pre_get_posts is an action, not a filter. You should be hooking in with add_action() instead of add_filter(), and the callback function shouldn&#039;t return anything.

The $query variable is passed by reference, so it isn&#039;t a copy of the $query variable inside WP_Query::get_posts(), it&#039;s a link directly to it. Any changes to $query inside the callback function will be applied to the variable in the calling function.</description>
		<content:encoded><![CDATA[<p>Just a minor correction: pre_get_posts is an action, not a filter. You should be hooking in with add_action() instead of add_filter(), and the callback function shouldn&#8217;t return anything.</p>
<p>The $query variable is passed by reference, so it isn&#8217;t a copy of the $query variable inside WP_Query::get_posts(), it&#8217;s a link directly to it. Any changes to $query inside the callback function will be applied to the variable in the calling function.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rich</title>
		<link>http://seanbehan.com/programming/intercepting-the-wordpress-loop/#comment-251</link>
		<dc:creator>Rich</dc:creator>
		<pubDate>Wed, 17 Nov 2010 16:48:52 +0000</pubDate>
		<guid isPermaLink="false">http://seanbehan.com/?p=968#comment-251</guid>
		<description>Just a quick thank you for this post. 
I was having the same issue with my menu disappearing because I was filtering my query on post_type and didn&#039;t realize the menu called the pre_get_posts filter.  I&#039;ve added logic to check for the menu query so it doesn&#039;t filter accordingly.</description>
		<content:encoded><![CDATA[<p>Just a quick thank you for this post.<br />
I was having the same issue with my menu disappearing because I was filtering my query on post_type and didn&#8217;t realize the menu called the pre_get_posts filter.  I&#8217;ve added logic to check for the menu query so it doesn&#8217;t filter accordingly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wp-coder-101</title>
		<link>http://seanbehan.com/programming/intercepting-the-wordpress-loop/#comment-241</link>
		<dc:creator>wp-coder-101</dc:creator>
		<pubDate>Thu, 04 Nov 2010 11:55:46 +0000</pubDate>
		<guid isPermaLink="false">http://seanbehan.com/?p=968#comment-241</guid>
		<description>Please switch to using posts_per_page, show_posts will be deprecated..

Your show_posts values end up being passed onto posts_per_page anyway...(because it replaces the older showposts).

http://codex.wordpress.org/Function_Reference/query_posts#Post_.26_Page_Parameters</description>
		<content:encoded><![CDATA[<p>Please switch to using posts_per_page, show_posts will be deprecated..</p>
<p>Your show_posts values end up being passed onto posts_per_page anyway&#8230;(because it replaces the older showposts).</p>
<p><a href="http://codex.wordpress.org/Function_Reference/query_posts#Post_.26_Page_Parameters" rel="nofollow">http://codex.wordpress.org/Function_Reference/query_posts#Post_.26_Page_Parameters</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nocash</title>
		<link>http://seanbehan.com/programming/intercepting-the-wordpress-loop/#comment-238</link>
		<dc:creator>nocash</dc:creator>
		<pubDate>Wed, 27 Oct 2010 18:45:58 +0000</pubDate>
		<guid isPermaLink="false">http://seanbehan.com/?p=968#comment-238</guid>
		<description>I experienced this same issue. It seems that menu  items are actually stored in the wp_posts table with a post type of nav_menu_item. When WordPress attempts to pull menu items from the database, it does so using the same type of query that triggers the pre_get_posts filter, which is now filtered to a specific category and prevents the query from finding any menu items.

A quick and dirty workaround is to add extra conditions to the function that is doing the pre_get_posts filtering to make sure it&#039;s really working with posts or pages.

&lt;code&gt;
function filter_homepage_posts($query) {
    if ( $query-&gt;post_type == &#039;page&#039; &#124;&#124; $query-&gt;post_type == &#039;post&#039; ) {
        $limit_number_of_posts = 5;
        $featured_category_id = get_cat_id(&#039;Reviews&#039;); // by cat name...
        if ($query-&gt;is_home) {
            $query-&gt;set(&#039;cat&#039;, $featured_category_id);
            $query-&gt;set(&#039;showposts&#039;, $limit_number_of_posts);
        }
    }
    return $query;
}
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>I experienced this same issue. It seems that menu  items are actually stored in the wp_posts table with a post type of nav_menu_item. When WordPress attempts to pull menu items from the database, it does so using the same type of query that triggers the pre_get_posts filter, which is now filtered to a specific category and prevents the query from finding any menu items.</p>
<p>A quick and dirty workaround is to add extra conditions to the function that is doing the pre_get_posts filtering to make sure it&#8217;s really working with posts or pages.</p>
<p><code><br />
function filter_homepage_posts($query) {<br />
    if ( $query-&gt;post_type == 'page' || $query-&gt;post_type == 'post' ) {<br />
        $limit_number_of_posts = 5;<br />
        $featured_category_id = get_cat_id('Reviews'); // by cat name...<br />
        if ($query-&gt;is_home) {<br />
            $query-&gt;set('cat', $featured_category_id);<br />
            $query-&gt;set('showposts', $limit_number_of_posts);<br />
        }<br />
    }<br />
    return $query;<br />
}<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bseanvt</title>
		<link>http://seanbehan.com/programming/intercepting-the-wordpress-loop/#comment-221</link>
		<dc:creator>bseanvt</dc:creator>
		<pubDate>Wed, 13 Oct 2010 00:13:49 +0000</pubDate>
		<guid isPermaLink="false">http://seanbehan.com/?p=968#comment-221</guid>
		<description>was you custom menu using a category?</description>
		<content:encoded><![CDATA[<p>was you custom menu using a category?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Julian</title>
		<link>http://seanbehan.com/programming/intercepting-the-wordpress-loop/#comment-220</link>
		<dc:creator>Julian</dc:creator>
		<pubDate>Tue, 12 Oct 2010 18:14:40 +0000</pubDate>
		<guid isPermaLink="false">http://seanbehan.com/?p=968#comment-220</guid>
		<description>Thanks - this is doing just what I was looking for - almost! The thing is, as well as filtering the posts correctly it stopped my custom menus from displaying in the sidebar - any idea why that would be or how to fix it?</description>
		<content:encoded><![CDATA[<p>Thanks &#8211; this is doing just what I was looking for &#8211; almost! The thing is, as well as filtering the posts correctly it stopped my custom menus from displaying in the sidebar &#8211; any idea why that would be or how to fix it?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

