WordPress Custom Post Type as Static Home Page

I’ve been searching the last couple of days for some sort of solution to this problem. I’m using custom post types in WordPress and I want to be able to specify my static home page to be one of my custom post types. In the WordPress Reading options it only lets you specify ‘Pages’, not any of your custom post types.

I came across this discussion here, but it didn’t lead to any kind of a solution.

Another possible is here, but it wasn’t a good solution because you had to create an actual page, and then use a custom template. A little too messy for my taste.

I also found this which was the closest one yet. I found out, that manipulating those options does work, but not as intended. The home page was auto-redirecting to the permalink of my custom post type. So, in principle, when I went to my home page I was seeing my custom post type, but when looking at the address bar, it actually just redirects to the permalink. This wasn’t the solution I was looking for.

Then I decided that if you could specify the post ID somewhere (in my theme settings) of the page I wanted to be the home page, it would be as simple as modify the query for my main loop. I came up with the following code placed in my main index.php file for my theme before the loop starts, and it seems to work perfectly.

$postId = 12345; // substitute with the ID of the post you want to show
if ( is_home() && '' != $postId ) :
$post = get_post( $postId );
query_posts( array( 'post_type'=>$post->post_type, 'p'=>$postId ) );
endif;

3 thoughts on “WordPress Custom Post Type as Static Home Page

  1. Oh thank you! You just saved me so much time and headache, and it works perfectly!

  2. After searching a lot for a solution, I’ve come out with this code:

    function add__to_dropdown( $pages, $r )
    {
    if(‘page_on_front’ == $r['name'])
    {
    $args = array(
    ‘post_type’ => ”
    );
    $items = get_posts($args);
    $pages = array_merge($pages, $items);
    }

    return $pages;
    }
    add_filter( ‘get_pages’, ‘add__to_dropdown’ );

    function enable_front_page_( $query )
    {
    if(” == $query->query_vars['post_type'] && 0 != $query->query_vars['page_id'])
    $query->query_vars['post_type'] = array( ‘page’, ” );
    }
    add_action( ‘pre_get_posts’, ‘enable_front_page_’ );

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>