I wrote plugin which uses Custom Post Types to create a series of pages. I have the code which adds the CPT to the "Reading" dropdown menu and it works great.
Here it is...
add_filter( 'get_pages', 'add_wpwebinar_front' );
function add_wpwebinar_front( $pages ) {
$my_wpwebinar_pages = new WP_Query( array( 'post_type' => 'wpwebinar' ) );
if ( $my_wpwebinar_pages->post_count > 0 ) {
$pages = array_merge( $pages, $my_wpwebinar_pages->posts );
}
return $pages;
}
The code works but if you select a Custom Post Type as the home page it redirects to the CPT actual page. Example... domain.com would redirect to domain.com/slug/pagename
In order to fix this, I found this code which I added...
function enable_front_page_stacks( $query ){
global $post, $wp_query;
if('' == $query->query_vars['post_type'] && 0 != $query->query_vars['page_id'])
$query->set('post_type', 'wpwebinar');
}
add_action( 'pre_get_posts', 'enable_front_page_stacks' );
This keeps the Custom Post Type as the main page. But... I have a few issues.
- If you select the default of show latest posts IT'S OK.
- If you select a Custom Post Type page as the front page IT'S OK.
The problem is when you select a normal PAGE as the frontpage. It inherits the Custom Post Type template and does not show the page content of course, because there's not code there for it.
I'm sure the fix is simple, but I have no idea what to change.
Ideas anyone? It would be greatly appreciated.
'rewrite' => array( 'with_front' => true, 'pages' => true, 'feeds' => true, 'slug' => 'post_type', ),
If you try changing'with_front'
tofalse
and'slug'
as well are you getting the same issues?