Rebuilding an author/writer website in WordPress.
I have a custom post type of books
. Working OK.
I'd also like my category base to be books
. Not working as yet.
So a book URL would be like:
And a category URL would be:
How can I achieve this?
My workaround is a category URL like this (working using Category Base =
books/category
):
Would prefer to add code in functions.php
or .htaccess
than use a plugin.
Thanks
Rebuilding an author/writer website in WordPress.
I have a custom post type of books
. Working OK.
I'd also like my category base to be books
. Not working as yet.
So a book URL would be like:
https://www.authorname/books/title
And a category URL would be:
https://www.authorname/books/fiction
How can I achieve this?
My workaround is a category URL like this (working using Category Base =
books/category
):
https://www.authorname/books/category/fiction
Would prefer to add code in functions.php
or .htaccess
than use a plugin.
Thanks
Share Improve this question edited Sep 30, 2019 at 10:55 Matt Sephton asked Sep 30, 2019 at 10:39 Matt SephtonMatt Sephton 1772 silver badges9 bronze badges1 Answer
Reset to default 3No, it's not safe to use the /books/
URL for both a category base and custom post type base. WordPress uses the URLs to determine what type of content to serve. If you've set up 2 different types of content at the same URL, it won't have any way to know which you're requesting, and if you end up with a book slug that's the same as a category slug, you'll really have conflicts.
To keep the URL types segregated but still logical, you could use URLS such as
CPT: example/book/title-of-a-single-book
Category: example/books/category-name
Or, perhaps something like
CPT: example/books/title-of-a-single-book
Category: example/book-categories/category-name
Or, continue using your workaround, example/books/category/category-name
, and they will all appear to be under "books."