2

I am looking to create two custom post types, one of which is a child of the other. Let's call them Authors and Books for simplicity.

Authors should be a top level URL and the landing page for them should show a list of all their authored books. So you'd have something like:

http://mysite.com/Shakespeare/ http://mysite.com/Shakespeare/Macbeth http://mysite.com/Shakespeare/Othello

How do I create something like this in Wordpress? I am fine if it requires custom coding, just not sure how to express the relationship of post types to Wordpress.

2

To me the most logical would be to have a "Book" custom post type, and then all the attributes of the books (Author, Collection, Genre, etc.) would be custom taxonomies.

Then for your URLs you could use some custom URL rewrite method to get what you want.

1

If it's a one-to-many relationship (an author can have multiple books, but a book can't have multiple authors), you can use the post_parent field in the posts table.

If it's a many-to-many relationship, you can use my Posts 2 Posts plugin.

To generate those urls, you can use the 'post_type_link' filter.

Finally, to match those URLs later, you can fall back to the page rewrite rule and manually parse the components (use the 'parse_request' action).

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.