Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Display Wordpress Custom Post Types on home page, add to functions.php
// Display Custom Post Types on home page, add to functions.php
add_filter( 'pre_get_posts', 'my_get_posts' );
function my_get_posts( $query ) {
if ( is_home() && $query->is_main_query() )
$query->set( 'post_type', array( 'news' ) ); //add cpt, in this case 'news' to array
return $query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.