At the moment I’m using a custom post type called ‘locations’ I would like to be able to put input fields into the custom post type that would store the information such as ( address, type, phone number, etc.. ) in a separate table called ‘markers’ So when a new post is made it will create a new entry in the table markers from the following input fields / have it updatable or removable when post is either changed or deleted.
I’m not sure where to start to get these linked together to work in such a fashion, I know how to make a insert.php file to add new locations and to create a database but not with wordpress in such a fashion. My apologies but I’m pretty new to SQL and PHP.
You should avoid creating more tables. Just do it if you really have a good reason to. Note that
wp_postmeta
can store practically any kind of data, and simply using theget_post_meta
function can do all the job in most cases.But if you must use another table, and taking it generally, then you’re looking for the
save_post
anddelete_post
hooks.Replicating custom fields
Because you mention custom fields, if you want to replicate the information from
wp_postmeta
to another table, you would do something like:The above applies also for the
delete_post
hook.Metaboxes
But, if you want to store the information directly on the other table, maybe metaboxes suits you better.
And then, for saving it:
And of course, you can do more verifications with the code above.
You have 3 options.
Just use the native custom fields in WordPress, unless you have a
good reason not to, they would suit you fine and work perfectly with
custom post types.
http://codex.wordpress.org/Custom_Fields
Create your own custom fields and tie them into your CPT using wpdb.
You need a good reason to do this instead of using option1.
http://codex.wordpress.org/Class_Reference/wpdb
Check out the pods framework, it is basically CPT’s with more
control over the DB.
Where ID is the id of the post you’re attaching the value for and VALUE is the meta value of the “translation” field.
Like I said, doable … but you’ll need a separate INSERT query for each post. You could dump all of these into a single text file and run the entire set in one pass if you want, otherwise it might take as much time as it would to just add the key through the WordPress UI in the first place.