[Resolved] Add new relationship item does not work as expected
This support ticket is created 5 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
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.