IF you want to use a custom post type archive as front page in your WordPress websites/blogs? Use following code in your theme’s functions.php file OR in site specific plugin.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
add_action("pre_get_posts", "custom_front_page"); function custom_front_page($wp_query){ //Ensure this filter isn't applied to the admin area if(is_admin()) { return; } if($wp_query->get('page_id') == get_option('page_on_front')): $wp_query->set('post_type', 'CUSTOM POST TYPE NAME HERE'); $wp_query->set('page_id', ''); //Empty //Set properties that describe the page to reflect that //we aren't really displaying a static page $wp_query->is_page = 0; $wp_query->is_singular = 0; $wp_query->is_post_type_archive = 1; $wp_query->is_archive = 1; endif; } |
This will call the archive-POSTTYPE.php
template correctly as well.
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.