Defining a default page for custom post type

You can kind of fake it before the main query is run with the pre_get_posts action:

function wpa84126_single_project_archive( $query ){
    if( ! is_admin()
        && $query->is_main_query()
        && $query->is_post_type_archive( 'new_projects' ) )
            $query->set( 'name', 'my-new-project' );
}
add_action( 'pre_get_posts', 'wpa84126_single_project_archive' );

Make sure to change new_projects to the actual name you’ve registered the post type under. It will still behave in every way as if it’s the archive page, but only that single post will be queried. You could save the slug in an option so you could change it without having to edit the code.

Leave a Comment