[wp-hackers] exclude category from main loops via plugin
Erick Hitter
ehitter at gmail.com
Mon Dec 13 13:17:16 UTC 2010
pre_get_posts is my preferred method. The hook fires before the
query executes, so there are no unnecessary database calls. The hook's first
argument is an object whose query_vars method is an array that you can add
your category exclusion (or any other query arguments) to.
Here's a sample:
function my_query( $query ) {
$query->query_vars[ 'category_name' ] = 'mycategory';
return $query;
}
add_action( 'pre_get_posts', 'my_query' );
Erick
On Mon, Dec 13, 2010 at 08:03, Alexander Höreth <a.hoereth at gmail.com> wrote:
> pre_get_posts
More information about the wp-hackers
mailing list