Support

Account

Home Forums General Issues How to Create a Custom URL Structure for Two Post Types in WordPress?

Solving

How to Create a Custom URL Structure for Two Post Types in WordPress?

  • Post Types:

    • Book
    • Chapter

    Desired URL Structure:
    I’d like to display the chapter post type under the book post type in the following structure:

    • Domain.com/book/jack-and-the-beanstalk/chapter/1
    • Domain.com/book/jack-and-the-beanstalk/chapter/intro

    What I’ve Tried:

    • Post Type Relationship:
      I created a relationship between the book and chapter post types using ACF. I added a rewrite rule in my theme to achieve the desired URL structure.
      Result: The rewrite rule didn’t work as expected.
    • Using Taxonomies:
      Since WordPress supports taxonomies in URLs, I tried the following:

      • Ensured each chapter was assigned a taxonomy corresponding to a book.
      • Created a script to automatically add a taxonomy for each book with a slug matching the book’s slug.

      Result: The URL didn’t return a 404 error, but it didn’t resolve to the chapter page. Instead, it redirected to the book page. For example:

      • Domain.com/book/jack-and-the-beanstalk/chapter/1 displayed the book page instead of the chapter page.

    The Problem:
    How can I correctly set up this URL structure using ACF to:

    • Link books and chapters.
    • Ensure chapters appear under their respective books in the URL.

    Any guidance or example code would be greatly appreciated!

  • Great guide! Creating custom URL structures can really improve your site’s SEO and overall user experience. If you’re looking to take your WordPress site to the next level with custom post types, optimized URL structures, or any other web development needs, feel free to reach out! Our web development services specialize in crafting tailored solutions to help businesses grow online.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.