I created a new custom type called 'books' and I created a Field using the Advanced Custom Fields plugin where I define the fields and create the records, with post names such as book1, book2, etc. I want to define a view for the elements of this particular custom type so when the visitor goes to website.com/books/book1 I will display information about book1. I tried defining single-books.php at the root of the theme but it didn't work. How can I define a template for the posts of a custom post?


  • single-books.php would be correct for a CPT named books. However you may want to double-check your code and adjust so the name is book singular. When you say you added the file and it "didn't work," what happened? Did you confirm that a different template was being used?
    – WebElaine
    May 22, 2019 at 17:07
  • Also, can you clarify your setup - are you actually creating individual "Book" posts in WP? From the way you worded your scenario it sounds like you might be trying to create just custom fields without associating them to a post. You'll need to create each actual "Book" post and you can then use ACF to add metadata for that post, and creating those posts is what actually allows you to go to example.com/books/book1 - it relies on having an actual post with the slug "book1".
    – WebElaine
    May 22, 2019 at 17:09
  • @WebElaine When I tried to access /books/name of post I got page not found. Any idea why?
    – Gonzalo
    May 23, 2019 at 7:00
  • @WebElaine regarding the second comment. Yes I created all the posts and their respective metadata using ACF.
    – Gonzalo
    May 23, 2019 at 7:01
  • After you registered your post type, did you visit the Settings > Permalinks page? This flushes permalinks and makes new permalinks work - you don't have to change any settings, but you do need to visit that page or use code to flush the rewrite rules.
    – WebElaine
    May 23, 2019 at 13:49

1 Answer 1


You can Use single-{posttype}.php for the single template.

And, if you have register your post type with the has_archive argument set to true, then you can use archive-{posttype}.php for your archive template.

You can check Template Hierarchy

Also for 404 Page, double check that page slug and post-type slug is NOT SAME. I mean check whether you have created any page with slug "books".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.