Hi all.
I wonder how to do this. I've made a custom post type called swimmers with a meta box containing some values of interest and everything is ok. I can insert and save data with no problem.
Now I've got a custom table in the database for the swimming competitions and I wonder if this could pull some of the data from the swimmer post type and from that custom meta box in order to prevent writing the same values over and over again.
In the specific, I'd like to get the swimmer post title (aka the swimmer name) and copy it into the custom table. When can I do it? While I'm saving the meta box or while I'm publishing the post? I think both are possible, but I'm not able to insert the value into the custom table.
This is my code (not working):
function update_table_with_swimmers(){
global $wpdb;
$table_name = $wpdb->prefix . 'swim';
$title = get_the_title();
$values = array(
'athlete' => $title,
);
$formats_values = array(
'%s',
);
$wpdb->insert( $table_name, $values, $formats_values );
}
add_filter( 'publish_post', 'update_table_with_swimmers' );
[Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]
What about retrieving values from meta box and copying them into that custom table?
Thank you in advance