I know I can set a static page as the homepage but is it possible to set a single custom post as the site front page?
I created a custom post type called “portfolio” where users can add all the work they have done as posts and I need one of those posts to display as the homepage, exactly as if you would set a static front page in the reading settings.
Thanks in advance!
You don’t want a post to be the front page, you want a custom post type entry to be the front page. Now that we have the terminology right, yes it’s possible.
A client once asked me to do the exact same thing. They had a custom post type they needed displayed on the front page. Doing so was as simple as adding a filter to allow them to select a “stack” (their custom post type) from the reading page:
function add_pages_to_dropdown( $pages, $r ){
if ( ! isset( $r[ 'name' ] ) )
return $pages;
if ( 'page_on_front' == $r[ 'name' ] ) {
$args = array(
'post_type' => 'portfolio'
);
$portfolios = get_posts( $args );
$pages = array_merge( $pages, $portfolios );
}
return $pages;
}
add_filter( 'get_pages', 'add_pages_to_dropdown', 10, 2 );
Then it’s just a matter of styling your templates to use the data correctly.