Home

Multiple Custom Post Types on Your Home page or Blog Page

Multiple Custom Post Types on Your Home page or Blog Page
Like Tweet Pin it Share Share Email

By default, WordPress is showing default post type on the blog page. If you are showing the latest blogs on the home page and wants to display multiple custom post types on your home page then you are at the correct place.

WordPress is providing action filters and using it we can change the default query and can show multiple post types with default post type.

Read Also: WordPress the_content hook functions

Copy below code and paste into your child theme’s functions.php file. The query is working with array so you need to update below query’s array. I want to show my custom post “Solutions” with default post type “Post” so I have updated like “array( ‘post’, ‘solutions’ )”.

add_filter( 'pre_get_posts', 'unityblogger_multiple_posts' ); 
function unityblogger_multiple_posts( $query ) 
{ 
    if ( is_home() && $query->is_main_query() ){
        $query->set( 'post_type', array( 'post', 'solutions' ) ); 
    } 
    return $query; 
        
}

After changing in above code place it into your functions.php page. Save it and then refresh your home page and you will see the magic.

Read Also: How To Modify WordPress Main Query
Read Also: Get Multiple Posts Data in Single WordPress Query

 

 

Thanks for reading our article. What Next?

Comments (1)

Leave a Reply

Your email address will not be published. Required fields are marked *

two × four =