I have a problem with Custom Post Types and pages names. Apparently this poses a conflict between them.
As it seems a CPT can not have the same name as a template file or a page. I can't seem to figure out why that is though. I foun some blogs and articles, but none of them really explains why this is, or what the solution for it is.
What's the case
I want to create a portfolio page. For that I created a CPT with Custom Post Type UI. I named that CPT portfolio. So far so good.
After that I create a page called porftolio and a template named portfolio.php
<?php $loop = new WP_Query(array('post_type' => 'portfolio', 'posts_per_page' => 10)); while ( $loop->have_posts() ) : $loop->the_post(); the_title(); echo '<div class="entry-content">'; the_content(); echo '</div>'; endwhile; ?>
So the page Portfolio will get the template of portfolio.php.
Apparently WordPress can't handle it if the CPT and page have the same name. Perhaps some one can explain why, because I can't seem to find it.
What happens if I navigate to my portfolio page? It skips every template file and goes straight to index.php. Something I of course don't want to see.
I'm not sure if that's what it's meant for, but I have tried an archive-posttype template, but that doesn't seem to work either.
If I rename the CPT to for instance projects, I can display the CPT's on the page Portfolio, but as soon as I use the
the_permaling(); I go to mysite.com/projects/singlecpt, and I don't want that. I want it to lead to mysite.com/portfolio/singlecpt
So, now what?
Well I'm hoping some one can help me out with this. I need a nudge in the right direction. I can't seem to put my finger on it why it won't work. All I want is a simple portfolio page with Custom Post Types. There must be a way to make this work, right? Or is this a massive bug in WordPress?