Skip to content

Instantly share code, notes, and snippets.

@roborourke
Created January 30, 2012 15:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roborourke/1704987 to your computer and use it in GitHub Desktop.
Save roborourke/1704987 to your computer and use it in GitHub Desktop.
Edit the main WordPress query to show items from a custom post type you specify
<?php
// replace 'post' with the id of the post type you want for your main listing
add_action( 'pre_get_posts', 'modify_main_query' );
function modify_main_query( $query ) {
if ( $query !== $wp_the_query || is_admin() )
return $query;
$query->query_vars[ 'post_type' ] = 'post';
return $query;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment