metabox with custom post type values

the old way

when i say “the old way” i mean my old way of doing this ,like i answered Need Help Finding a WordPress E-Commerce Plugin That Utilises Custom Post Types before about creating relations between custom post types that i used custom fields for that
meaning:

  • Author will have two custom fields (book_ids[], photo_ids[])
  • Books will have two custom fields (author_ids[], photo_ids[])
  • Photos will have two custom fields (book_ids[], author_ids[])

so this makes the query very easy like this:

//lets say you are need to get all books of an author

$q= array( 
    "POST_TYPE"=>'books',
    'meta_key' =>'author_ids', 
    'meta_compare' => '=' 
    'meta_value' => $author_id,
    );
    query_posts($q);

and as for the meta boxes lets say for the authors edit page you can create a multi select dropdown of the books and save the ids, and the save for photos.

Different approach

I’m currently working on a site that need relations like so but instead of creating CPT (custom post type) for all 3 , in your case, i create the photos,books as custom post types
and authors and custom taxonomy with extra fields added to them witch makes
it easier to connect between authors to photos and book, and all i have left is to create relations between photos and books by custom fields like before, so basically what I’m doing is using custom taxonomy as a custom post type.

Hope this makes sense (at least some of it).
this way you can connect