I've created a custom post type: tutorials
using generatewp.com generator and registered it with register_post_type()
.
I'm querying the list of tutorials in a custom page template like that:
<?php $query = new WP_Query('post_type=tutorial'); ?>
<?php if($query->have_posts()) : ?>
<?php while($query->have_posts()): the_post(); ?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<p><?php the_excerpt(); ?></p>
<?php endwhile(); ?>
<?php endif; ?>
To target single tutorial template I've created a file single-tutorial.php
, placed a loop inside it, and fired the tutorial permalink in the browser.
The single-tutorial.php
file is ommited from Template Hierarchy and goes directly to index.php.
The premalink is for example: http://example.com/tutorial/tutorial-name/
.
index.php
content is loaded instead of single-tutorial.php
Why is that? Any help very appreciated.