[wp-hackers] pre_get_posts alternatives

Dan Smart dan at dansmart.co.uk
Mon Sep 27 13:25:43 UTC 2010


Have you tried checking for the post type first with get_post_type() ?

Dan

(Sent from iPhone)
Dan Smart - Web Developer
www.dansmart.co.uk

On 27 Sep 2010, at 14:20, 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?
> 
> nb - I read http://www.listware.net/201007/wordpress-hackers/75304-wp-hackers-pregetposts-problem.html
> and tried "request" and "parse-request" - they don't seem to be
> working. Sample of existing code below.
> 
> add_action( 'pre_get_posts', 'amp_filter' );
> function amp_filter( $query )
> {
>    if ( is_tax('locations') ) {
>        $query->set( 'posts_per_page', 25 );
>    return $query;
> }
> 
> Cheers,
> 
> Chris.
> _______________________________________________
> 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