438 posts
  • Has been part of the Envato Community for over 3 years
  • Sells items exclusively on Envato Market
  • Located in United States
christopherjon says

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?

1012 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+6 more
wizylabs says

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

438 posts
  • Has been part of the Envato Community for over 3 years
  • Sells items exclusively on Envato Market
  • Located in United States
christopherjon says

Nope,

custom post type

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

2450 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $100+ on Envato Market
  • Has referred 100+ members
  • Has been a beta tester for an Envato feature
+3 more
digitalimpact says

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 :)

438 posts
  • Has been part of the Envato Community for over 3 years
  • Sells items exclusively on Envato Market
  • Located in United States
christopherjon says

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.

3445 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $750,000+ on Envato Market
  • Located in United States
  • Helps us moderate the forums
+10 more
sevenspark Moderator says

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.

438 posts
  • Has been part of the Envato Community for over 3 years
  • Sells items exclusively on Envato Market
  • Located in United States
christopherjon says

Thanks, digging through the admin junk now.

1 post
  • Has been part of the Envato Community for over 3 years
johnsoda says

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?

438 posts
  • Has been part of the Envato Community for over 3 years
  • Sells items exclusively on Envato Market
  • Located in United States
christopherjon says

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. :)

2 posts
  • Has been part of the Envato Community for over 5 years
  • Has collected 10+ items on Envato Market
dom4biz says
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.

by
by
by
by
by
by