[wp-hackers] pre_get_posts alternatives
Christian Foster
christian.foster at gmail.com
Mon Sep 27 17:45:18 UTC 2010
That works well - thank you,
Chris.
On Mon, Sep 27, 2010 at 4:05 PM, scribu <mail at scribu.net> wrote:
> 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;
> }
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list