I have registered two custom post types using the following code
add_action( 'init', 'create_post_types' );
function create_post_types() {
register_post_type( 'sector', array(
'labels' => array(
'name' => __( 'Sectors' ),
'singular_name' => __( 'Sector' )
),
'public' => true,
'has_archive' => true,
'supports' => array( 'title', 'editor' )
));
register_post_type( 'player', array(
'labels' => array(
'name' => __( 'Players' ),
'singular_name' => __( 'player' )
),
'public' => true,
'has_archive' => false,
'supports' => array( 'title', 'editor' )
));
}
This correctly creates the post types in the Wordpress admin & I am able to create new posts. So far so good. The problem comes when trying to view a single post or list these posts within an archive.
In my attempts I have created archive-sector.php
and single-sector.php
... following the documentation I would expect the code in the 'single' file to display when I visit a URL such as this: http://mydomain.com/sector/a-single-post/
But it doesn't it simply renders the code from the index.php
. Which is rather frustrating. Can anyone point out where I am going wrong.
What confuses me further is I am able to reference the posts within a custom WP_Query
within my front-page.php
:
<?php
$args=array(
'post_type' => 'sector',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$get_sectors = new WP_Query($args);
if( $get_sectors->have_posts() ) {
while ($get_sectors->have_posts()) : $get_sectors->the_post();
?>
<div class="medium-6 columns">
<div class="panel">
<h3>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</h3>
</div>
</div>
<?php
endwhile;
}
wp_reset_query();
?>
This displays the post titles no problem!
Any suggestions would be great as I'm at a loss with this one!