Created
October 21, 2015 09:37
-
-
Save jonschr/f091906a76c2078cbb0a to your computer and use it in GitHub Desktop.
Modifying a query before it begins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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