Skip to content

Instantly share code, notes, and snippets.

@bueltge
Created May 30, 2011 09:25
Show Gist options
  • Save bueltge/998648 to your computer and use it in GitHub Desktop.
Save bueltge/998648 to your computer and use it in GitHub Desktop.
Example for add a Custom Post Type to the WordPress Loop
// add custom post type to wp loop
add_action( 'pre_get_posts', 'add_to_query' );
// ads to query
function add_to_query( $query ) {
if ( is_admin() || is_preview() )
return;
// only filter on front page
if ( is_home() || is_front_page() && ( FALSE == $query -> query_vars['suppress_filters'] ) ) {
$query->set( 'post_type', array( 'post', 'my_post_type' ) );
return $query;
}
@bueltge
Copy link
Author

bueltge commented Jun 9, 2011

Hook int correcty is an action --> add_action(); not add_filter() - Sorry; its fixed on example

@gr4y
Copy link

gr4y commented Jun 9, 2011

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment