{"id":2467539,"date":"2011-12-23T14:35:34","date_gmt":"2011-12-23T14:35:34","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/bug-custom-post-type-name-conflict\/"},"modified":"2016-08-20T04:01:08","modified_gmt":"2016-08-20T04:01:08","slug":"bug-custom-post-type-name-conflict","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/bug-custom-post-type-name-conflict\/","title":{"rendered":"[bug?] Custom Post Type name conflict."},"content":{"rendered":"<p>Hello everybody,<\/p>\n<p>I have a problem with Custom Post Types and pages names. Apparently this poses a conflict between them.<\/p>\n<p>As it seems a CPT can not have the same name as a template file or a page. I can&#8217;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.<\/p>\n<p><strong>What&#8217;s the case<\/strong><br \/>\nI want to create a portfolio page. For that I created a CPT with <a href=\"https:\/\/wordpress.org\/extend\/plugins\/custom-post-type-ui\/\">Custom Post Type UI<\/a>. I named that CPT portfolio. So far so good.<\/p>\n<p>After that I create a page called porftolio and a template named portfolio.php<\/p>\n<p><em>portfolio.php<\/em><\/p>\n<pre><code>&lt;?php\n\t$loop = new WP_Query(array(&#039;post_type&#039; =&gt; &#039;portfolio&#039;, &#039;posts_per_page&#039; =&gt; 10));\n\twhile ( $loop-&gt;have_posts() ) : $loop-&gt;the_post();\n\t\tthe_title();\n\t\techo &#039;&lt;div class=&quot;entry-content&quot;&gt;&#039;;\n\t\tthe_content();\n\t\techo &#039;&lt;\/div&gt;&#039;;\n\tendwhile;\n?&gt;<\/code><\/pre>\n<p>So the page Portfolio will get the template of portfolio.php.<\/p>\n<p><strong>The problem<\/strong><br \/>\nApparently WordPress can&#8217;t handle it if the CPT and page have the same name. Perhaps some one can explain why, because I can&#8217;t seem to find it.<\/p>\n<p>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&#8217;t want to see.<\/p>\n<p>I&#8217;m not sure if that&#8217;s what it&#8217;s meant for, but I have tried an archive-posttype template, but that doesn&#8217;t seem to work either.<\/p>\n<p>If I rename the CPT to for instance projects, I can display the CPT&#8217;s on the page Portfolio, but as soon as I use the <code>the_permaling();<\/code> I go to mysite.com\/projects\/singlecpt, and I don&#8217;t want that. I want it to lead to mysite.com\/portfolio\/singlecpt<\/p>\n<p><strong>So, now what?<\/strong><br \/>\nWell I&#8217;m hoping some one can help me out with this. I need a nudge in the right direction. I can&#8217;t seem to put my finger on it why it won&#8217;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?<\/p>\n<p>Thanks.<\/p>\n<p>Mark<\/p>\n","protected":false},"template":"","class_list":["post-2467539","topic","type-topic","status-closed","hentry","topic-tag-conflict","topic-tag-cpt","topic-tag-custom-post-type","topic-tag-custom-post-type-archive","topic-tag-custom-post-type-pagination","topic-tag-name","topic-tag-page","topic-tag-walker","topic-tag-wp_list_pages"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/2467539","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/2467539\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=2467539"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}