2

I have created a custom post type 'books', but I don't want to use archive-books.php to list the books. I need to use a static page to list my books because I would like to add content using the content editor.

I would like this structure:
www.example.com/books ----> It is a static page
www.example.com/books/book-title ---> it is single post type

The problem is that I get a 404 when I try to go into my single post.

Can you help me?

2
  • I'm assuming your post type has a URL rewrite (when registering it) as 'books' ?
    – Howdy_McGee
    Oct 3, 2014 at 16:18
  • 1
    Yes, the url rewrite is 'books' Oct 3, 2014 at 17:16

2 Answers 2

4

Set has_archive to false. In order to keep the URL structure you want (/books/book-name), you'll need to add a rewrite rule:

'rewrite' => array('slug' => 'books'),
1
  • Perfect!! That was the problem. Thank you very much :) Oct 3, 2014 at 18:08
0

If you're still experiencing troubles after using Johannes' solution:

Try to update your permalink structure in the WordPress backend! Most often you just have to re-save the settings. If this doesn't help, change the permalink structure and save it. Then undo the changes and save your original structure. This process will force WordPress to update all URLs!

1
  • 1
    Just visiting the permalinks settings page flushes rewrite rules, no need to save or change anything.
    – Milo
    Jan 7, 2017 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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