Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom post type running called services:

// Services
function services_cpt() {
  $labels = array(
    'name'               => _x( 'Services', 'post type general name' ),
    'singular_name'      => _x( 'Service', 'post type singular name' ),
    'add_new'            => _x( 'Add New', 'production' ),
    'add_new_item'       => __( 'Add New Service' ),
    'edit_item'          => __( 'Edit Service' ),
    'new_item'           => __( 'New Service' ),
    'all_items'          => __( 'All Services' ),
    'view_item'          => __( 'View Service' ),
    'search_items'       => __( 'Search Services' ),
    'not_found'          => __( 'No services found' ),
    'not_found_in_trash' => __( 'No services found in the Trash' ), 
    'parent_item_colon'  => '',
    'menu_name'          => 'Services'
  );
  $args = array(
    'labels'        => $labels,
    'description'   => 'Holds our services and service specific data',
    'public'        => true,
    'menu_position' => 5,
    'supports'      => array( 'title', 'editor', 'thumbnail' ),
    'has_archive'   => true,
  );
  register_post_type( 'services', $args ); 
}
add_action( 'init', 'services_cpt' );

I would like to use a page template to display the posts instead of archive-services.php. I have built the following page template:

<?php
/*
Template Name: Services
*/
// Get header
get_header(); ?>

<div id="primary">
<?php $loop = new WP_Query( array( 'post_type' => 'services', 'posts_per_page' => -1 ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

<section class="col third">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('medium'); ?></a>
<h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<?php the_content(); ?>
</section>

<!-- End loop -->
<?php endwhile; wp_reset_query(); ?>

<!-- End primary -->
</div>
<?php get_footer(); ?>

When I go to the page on the front-end, it's displaying the default archive.php. I can't figure out what I'm doing wrong. Any help is much appreciated :)

share|improve this question
    
Silly question, but did you create a page in the admin that uses the template you created? –  gdaniel Feb 4 at 15:14
    
Not a silly question at all, but yes... I have set up the page "services" and assigned the services template to that page. –  Squideyes Feb 4 at 15:31
    
There was a conflict with register_post_type( 'services', $args ); and the page url /services. I've changed it to "our_services" and refreshed the permalinks. Everything is working perfectly now. Thank you for the @gdaniel for pointing me in the right direction. –  Squideyes Feb 4 at 15:45
    
Glad you got it to work. –  gdaniel Feb 4 at 16:34

1 Answer 1

up vote 2 down vote accepted

You are probably getting a rewrite conflict with the has_archive argument here:

 $args = array(
    'labels'        => $labels,
    'description'   => 'Holds our services and service specific data',
    'public'        => true,
    'menu_position' => 5,
    'supports'      => array( 'title', 'editor', 'thumbnail' ),
    'has_archive'   => true,
  );

Set has_archive to false if you do not want the automatically generated archive.

I don't really see the logic of not using the template system though.

share|improve this answer
    
This hasn't made a difference unfortunately. –  Squideyes Feb 4 at 15:36
1  
Did you flush rewrite rules? –  s_ha_dum Feb 4 at 15:45
    
See comment above ;) –  Squideyes Feb 4 at 15:46
    
Your comment doesn't answer, y question. –  s_ha_dum Feb 4 at 16:12
    
Changing register_post_type( 'services', $args ); to register_post_type( 'our_services', $args ); solved the issue. There was a conflict somewhere along the way. Unless you can think of a better way to avoid this? I'm happy either way :) –  Squideyes Feb 4 at 16:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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