Adding custom post type to loop

You need something like this in you functions.php file, I’m using the action Pieter suggested.

function add_custom_post_type_to_query( $query ) {
    if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'post_type', array('post', 'article') );
    }
}
add_action( 'pre_get_posts', 'add_custom_post_type_to_query' );

You can read more about the pre_get_posts in the docs.

Leave a Comment