Support

Account

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

Unread

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!

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.