Search code examples
phpwordpresscustom-post-type

Link to custom archive page links to page-template instead


On my page-projects.php template page I am outputting image posts from my CPT 'projects'.
I want to add a 'see all' link to my 'archive-projects.php (using: echo get_post_type_archive_link('/projects');), but it's linking to the same page-projects.php that I am on...

  • created template page in root called page-projects.php
  • in dashboard the page is 'photography' with slug of 'projects' and is assigned project template(page-projects.php) from 'page attributes' meta-box
  • CPT is 'projects', and each project is assigned project template(page-projects.php) from 'page attributes' meta-box
  • created archive-projects.php in root and in CPT code I have added for archive 'has_archive' => true

Why is it linking to my custom post type page that I am already on and not my custom post type archive page?


Solution

  • If your page who list projects slug is projects AND your archive slug is also projects WordPress will always display your page.

    The archive page need to have a different slug.