Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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