Custom post types have a different hierarchy than pages or posts.
They’ll use single-{{post_type}}.php
and fall back to single.php
. Post type archives will use archive-{{post_type}}.php
and fall back to archive.php
.
Your question isn’t super clear, but if you want your custom post type’s singular page to use the page-testimonials.php
template, rename it to single-testimonials.php
.
I suspect, however, that you meant that page-testimonials.php
was display a list of the testimonials. In which case, rename it to archive-testomonials.php
and it should work fine. What happened before is you saw the permalink yoursite.com/?page_id={{some_number}}
. Which works — that’s always going to be a page, but with the post type as you registered it (with 'has_archive' => true
) yoursite.com/testimonials
attempts to display the custom post type archive.
A final note: if you did any query modifications or secondary queries to get the testimonials
post type in your page-testimonials.php
template, you can remove those. WordPress will take care of making sure the correct items are available in the archive-{{post_type}}.php
template.
You should also have a look at the template hierarchy