I am dynamically setting the title of a custom post when the post is added or saved. This works fine with the following code:
add_action('save_post', 'myplugin_save_postdata',30,2);
/* When the post is saved, saves our custom data */
function myplugin_save_postdata($post_id,$post) {
global $wpdb;
if($post->post_type == 'catalog-item')
{
$mydata1 = get_post_meta($post_id,'wpcf-part',true);
$mydata2 = get_post_meta($post_id,'wpcf-size',true);
$mydata3 = get_post_meta($post_id,'wpcf-name',true);
$mytitle = $mydata3 . " - " . $mydata1;
$where = array( 'ID' => $post_id );
$wpdb->update( $wpdb->posts, array( 'post_title' => $mytitle ), $where );
}
}
This works when I go to the custom post type and add or edit a post. This does not work when I add a post from a custom relationship field. For example I have a custom post type "product". Each product can have multiple "catalog Item"s. When I add a catalog item normally, the post title save just fine. When I add a catalog item on the product page using the relationship field, the title does not save. It only has a -. It's lik the wpcf-part and wpcf-name are missing when adding the catalog item from the relationship field on the product page.
Thank you for your help. Although, I could not make toolset_association_created hook work, I was able to create a work around by using WP's save_post hook on the products type.