Hi,
I am using this method to join two meta fields (first and last name) and insert them as the title. I am using a front-end form to make changes. The front-end form works well and all of the data is captured as expected. I am having problems with the function to insert the post title though. I am using this:
function set_member_meta_title( $data , $postarr ) {
if($data['post_type'] == 'obh_member_meta') {
$first_name = get_post_meta($postarr['ID'],'obh_member_first_name',true);
$last_name = get_post_meta($postarr['ID'], 'obh_member_last_name' , true);
$title = $first_name . ' ' . $last_name;
$post_slug = sanitize_title_with_dashes ($title,'','save');
$post_slugsan = sanitize_title($post_slug);
$data['post_title'] = $title;
$data['post_name'] = $post_slugsan;
}
return $data;
}
add_filter( 'wp_insert_post_data' , 'set_member_meta_title' , '500', 2 );
The funny thing is that it inserts the last value for the fields. For instance if I save Joe as the first name, it does nothing, but when I go back and change Joe to Frank, it writes Joe as the title while changing the actual first name in the DB to Frank.
I thought it was a priority issue so I have played with them from 1-999 with little to no effect.
I'm at a loss. Any thoughts?
Thanks!