[wp-hackers] pre_get_posts alternatives
scribu
mail at scribu.net
Mon Sep 27 15:05:48 UTC 2010
On Mon, Sep 27, 2010 at 4:20 PM, Christian Foster <
christian.foster at gmail.com> wrote:
> Hi,
>
> I am hooking into pre_get_posts to filter certain post types on
> taxonomy templates however I have realised this is also affecting any
> other get_posts. Is there an alternative that will only effect the
> main loop?
>
You can check for the global $wp_query object:
add_action( 'pre_get_posts', 'amp_filter' );
function amp_filter( $query )
{
if ( $query === $GLOBALS['wp_query'] && is_tax('locations') ) {
$query->set( 'posts_per_page', 25 );
return $query;
}
More information about the wp-hackers
mailing list