I have two custom post types, Books and Authors. Now, each book will have its corresponding author(s). I know how to associate books with authors using custom metas.

However, over time, there will be a lot of books and corresponding authors. Which would be the best UI control to show a list of authors to select from, hopefully in a compact manner?

  • Way not use authors as a custom taxonomy?
    – Bainternet
    Nov 13, 2012 at 16:14

2 Answers 2


I would add a meta box to the books custom post type, containing an input field with autocompletion, to select the author from the existing authors.

You can also use a standard dropdown-field, but it gets crowded if you have a lot of authors.

On the save_post action, add a meta_data field with the ID of the author to the book:

update_post_meta($book_id, '_book_author', $author_id, $prev_value);

Also, to have a good overview, I would add a metabox to the author custom post type, containing all the books assigned to this author. You can either query them directly (SELECT 'post_id' FROM wp_postmeta WHERE meta_value = '$author_id' AND meta_key = '_book_author'), and outupt a list with the links to the edit.php of the corresponding book, or you could save the meta_data for the books as well (when saving the book), something like:

add_post_meta( $author_id, '_books_by_this_author', $book_id );

If you choose the second version, be sure to handle the redundant data right - you could end up with a lot of dead links if you do not delete the post_meta when deleting or updating a book.

I assume you know how to add meta_boxes and the hook to the save_post action? if not, check out this article

I did not explain everything in detail here - as well as I did not write the query in the best Wordpress way, I just wanted to give you my input on how to solve the problem, not to explain it from scrath. if you need more help on that, please let me know.

  • Yes fischi, that's the solution I came up with too. Right now, I'm using jquery suggest that comes with WP, and an ajax function to return the list of authors. I show the currently selected authors as a list of checkboxes. I too think that this is the most elegant solution.
    – AgilE
    Nov 13, 2012 at 13:29

Another way to go would be to use scribu's Posts 2 Posts plugin, which allows you to connect different post types together. Using the plugin to create a connection automatically gives you meta boxes to connect authors to books, then you can customize your theme pull the connection information.

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.