Support

Account

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

Helping

How to display Date Picker values beetween Custom Post Type to edit Profile User

  • Hi Everybody, Sorry for my English !

    I’m beginner with ACF :
    I have a DatePicker ACF (and other field User Field) in my custom post type “Suivi”. I have a new post (choice of my client) for each client, each weeks !
    My client wants changed the values of DatePicker. After, he wants to display the new date saved (in the Cutom Post Type Suivi), to the page Edit Profil for the specify user (i have created & displayed here the same DatePicker where i can save the end-date of the subscription) (i found the user with $user_acf = get_field(‘user’, $post->ID);).
    When i save, it’s okai, but i have some error with $date->format(“d/m/Y”)…

    Fatal Error format..

    My format in ACF Field Plugins is d/m/Y in back and front end…

    My Code :

    function save_date() {
        $user_acf = get_field('user', $post->ID);
        $dateChanged = get_field('date_de_fin_dabonnement', $post->ID);
        $date = new DateTime($dateChanged);
        $date = $date->format('d/m/Y');
        
        update_field('date_de_fin_dabonnement', $date, 'user_'.$user_id);
    }
    add_action('save_post_suivis_physique', 'save_date', 10);

    Thanks for help !
    Peace =)

  • 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)

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘How to display Date Picker values beetween Custom Post Type to edit Profile User’ is closed to new replies.