How to Display Custom Post Types on The WordPress Front Page

How to Create Custom Post Types in WordPress

One advantage of using custom post types is that it keeps your custom content types away from your regular posts. However, if you would like them to display among your regular post, then you can do so by adding this code into your theme’s functions.php file or a site-specific plugin:

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

Don’t forget to replace movies with your custom post type.

Easiest way add for example php code to WordPress is using WordPress Code Snippet plugin.

Leave a Comment

Your email address will not be published.

Scroll to Top