I basically have the same problem like in this question, but the correct answer doesn't work for me. Yes, I get a list of posts from my CPT, but the archive-{post-type}.php is not used to render the page. It still uses the index.php. Any help would be great!

This is my code:

add_action('pre_get_posts', 'my_front_page');
function my_front_page($wp_query) {
  $post_type = 'foobar';

  if ( $wp_query->get('page_id') == get_option('page_on_front') ) {
    $wp_query->set('post_type', $post_type);
    $wp_query->set('page_id', '');

    // Fix conditional functions like is_front_page or is_single
    $wp_query->is_page = 0;
    $wp_query->is_singular = 0;

2 Answers 2


Why don't you try using a home.php file and place your desired loop/query within that file or alternatively use get_template_part to retrieve a file that contains your loop.

Can you please show us your code?

What I frequently do is structure my index.php like so,

<?php get_header(); ?>

    <?php if ( is_home() ) {


        } else {

           //run standard/default loop here


<?php get_footer(); ?>

Then within home.php you can do literally whatever you like,

$args = array( 'posts_per_page' => 10, 'post_type' => 'custom_post_type' );
$wp_query = new WP_Query( $args ); 
while ( $wp_query->have_posts() ) : $wp_query->the_post();
 //get your title, content, tags, etc

With this approach you are NOT required to set a static front page within your dashboard settings under the normal Settings -> Reading -> Front page displays section.

Note: This is not the only way to achieve what you want, but a reliable method without having to resort to using any filters, if you're not comfortable with using them or in the event you're having trouble (of course saying this without seeing your code so far).

  • I updated my question with the code snippet I'm using Oct 22, 2012 at 11:40

I would try this: save your archive-{custom-post-type}. php as template-{custom-post-type}.php then post a comment like the below into the file before you call your header - change the Template Name from "CPT" to whatever you want.

Now create a new page and use this template file to display the content. Then go to your settings -> reading page and set Front page displays: as you new page

 * Template Name: CPT Archive

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.