How to create custom field with multiple checkbox and reference it to another mysql table in wordpress?

I have a mysql database for various music genre. What I want to do is, I want to relate all my blog posts to specific genre. For that I have to add custom field in wordpress add/update post form. This will include the custom meta box with list of checkboxes. These checkboxes are generated using the “genre” table. I also want to allow multiple checkbox selection.

In database it should be stored in a table like this

Read More
post_genre_master
------------------------
id (auto generate)
post_id
genre_id

I tried to create a code for static values like this the one on below link but for empty values, but this lose the array indexes when some checkboxes are not selected.

http://pastebin.com/7RPh9Qii

The “act_id” in this code sample is actually “genre_id”

Related posts