Skip to content

Instantly share code, notes, and snippets.

@jonschr
Created October 21, 2015 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonschr/f091906a76c2078cbb0a to your computer and use it in GitHub Desktop.
Save jonschr/f091906a76c2078cbb0a to your computer and use it in GitHub Desktop.
Modifying a query before it begins
<?php
// Don't include the opening php tag
// Modify a query conditionally in functions.php
function prefix_modify_query( $query ) {
if ( $query->is_home() && $query->is_main_query() && !is_admin() ) {
$query->set( 'post_type', 'my_cpt_name' );
}
}
add_action( 'pre_get_posts', 'prefix_modify_query' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment