Support

Account

Home Forums Backend Issues (wp-admin) How to display Date Picker values beetween Custom Post Type to edit Profile User Reply To: How to display Date Picker values beetween Custom Post Type to edit Profile User

  • function custom_save_date( $post_id ) 
    {
    	// get user from user field
    	$user = get_field( 'user', $post_id );
    	
    	// get user id from user field
    	$user_id = $user['ID'];
    
    	// get date changed field
    	$date_changed = get_field( 'date_de_fin_dabonnement', $post_id );
    	$date = new DateTime( $data_changed );
    	
    	// set format
    	$date = $date->format('d/m/Y');
    	
    	// update user field
    	update_field( 'date_de_fin_dabonnement', $date, 'user_' . $user_id );
    }
    // acf save post hook
    add_action('acf/save_post', 'custom_save_date', 15);

    ACF has its own hook. You can use them for your fields. Also, you forgot the global $post as well as the user in your example. I have not tested the code AND sorry for my english! 🙂

    If you using an other output from user field, just change the output in line 7 and 17.

    Useful links:
    acf/save_post
    ACF user field (first answer from John)