Skip Navigation

[Resolved] Custom posts to home page

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 2 replies, has 2 voices.

Last updated by fahimS-2 1 year, 10 months ago.

Author
Posts
#2572009

I have created an archive with Toolset for the Home page. I want the home page archive to show my custom posts too. But it is only showing the posts. How can I show the custom posts too in my home page archive?

#2572091

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

It is not possible to add extra post types to the blog archive from within the UI, you need to overwrite the default setting of post with code, using the standard WordPress hook pre_get_posts (https://developer.wordpress.org/reference/hooks/pre_get_posts/).

Here's an example of the kind of code you would require (you can add a code snippet at Toolset > Settings > Custom Code; this snippet doesn't need to run on the back end):

add_action( 'pre_get_posts', 'ts_mod_blog_archive' );
function ts_mod_blog_archive( $query ){

    if ( $query->is_home() && $query->is_main_query() )
    {   
        // pass an array of post type slugs to include on blog archive
        $query->set( 'post_type', array( 'post', 'thing' ) );
    }
}

You need to edit the array to include the slugs of the post types you would like to include in the blog archive.

#2572117

My issue is resolved now. Thank you!