WP Custom Post Type as Static Home Page

I’d like to be able to select a custom post as the static home page through the admin Settings -> Reading -> Front Page Displays.

I’m sure this can be done with a filter or some wack-a-doo hack but I can’t figure it out.

Any ideas on this?

you mean like an archive but for a custom post type? if so, why dont you just use the index.php for that

Nope,

custom post type

WP only allows pages to be used as a static home page and that doesn’t suit my needs.

You could also create a page template, query your custom post type in it, and create a page using that template.

Use that page as your frontpage. Done :slight_smile:

I considered that route… which might be what I’ll have to do but it’s creating a bunch of unnecessary steps I’d like to avoid if possible.

My best guess is using a filter. I just happen to suck with WP filters and I’m not sure what function is doing the actual call on the setting page that pulls up a list of pages to select from. Using a filer it should be possible to change the call to pull up both pages and custom posts.

Looks like I might be spending all day digging through the core files to figure it out.

Doing a few quick searches I think the filter you need is wp_dropdown_pages

Check out:

wp-admin/options-reading.php line 60

wp-includes/post-template.php line 709 wp_dropdown_pages()

Only issue is that the filter looks like it filters a list that is used all over the place in WordPress. So you’ll want to limit the filter based on the name passed in the arguments if possible.

Thanks, digging through the admin junk now.

Hey hi!
Very interesting. i’m trying to do this since a couple of days…i’ve tried few things but i didnt solved how to do it…

Have you been able to do it?

It’s still on the list of things to be done.

I was hoping somebody smarter than I am would come along and post some easy code. :slight_smile:

add_filter( 'get_pages',  'add_my_cpt' );

function add_my_cpt( $pages )
{
     $my_cpt_pages = new WP_Query( array( 'post_type' => 'my_cpt' ) );
     if ( $my_cpt_pages->post_count > 0 )
     {
         $pages = array_merge( $pages, $my_cpt_pages->posts );
     }
     return $pages;
}

add the above code to functions.php and you are ready to go. Now u will be able to see your custom post type pages in the dropdown.

digitalimpact said

You could also create a page template, query your custom post type in it, and create a page using that template.

Use that page as your frontpage. Done :slight_smile:

+1

the problem with the solution given is that if your homepage will redirect to to the url of the post type.

Example…

home page url - http://www.example.com

would redirect to - http://www.example.com/post-slug/custom-post-page

I’m looking for a solution, but haven’t found it yet.