Add custom post types to the Loop by adding an action to `pre_get_posts`

[deprecated permalink=”http://uncommoncontent.com/2012/01/28/add-custom-post-types-to-the-loop”]

I wrote this function to allow me to use custom post types in my blog without having to fine-tune each template for their inclusion. It checks the query to see if `post_type` is set; if it is not set (as it would be on a specific post type’s archive page), it includes all public post types.


* 26 August 2010: Changed `! is_page() && ! is_single()` to `! is_singular()`.

6 thoughts on “Add custom post types to the Loop by adding an action to `pre_get_posts`”

  1. You, my friend, are a master. I have been searching for days on end… I was trying to include a custom post type categorie in the category.php-view, but these aren’t queried by default. This does the trick! Thanks a million!

Leave a Reply