Home Forums General Issues get acf field values from user profile and pass to create post form


get acf field values from user profile and pass to create post form

  • get ACF field values from the user profile and pass them to create a post form using the user relationship field. So I have a User Creation Field that saves extra information to the user’s profile. I would like to transfer all those data in the post creation form once the User relationship field has value.

    Here is my user relationship field.
    and the fields the i need to call to this form on my front end.

  • If you want these auto populated before the form is submitted then you need to create an AJAX request to get the values and populated the fields. I have an example of doing select fields here that would need to be modified to your needs

    A simpler solution would be

    1) Add an acf/prepare_field filter for the contract number and email fields. This filter would have to get the get the post type of the post being edited. If the post being edited is the proposal post type AND the field does not have a value THEN return false so the field does not need to be entered.

    2) Create an acf/save_post action, priority > 10. Here you get the ID of the value entered in the user relationship field, get the values from that user and update the other two fields with the correct values.

  • $post_data = array(
    ‘post_title’ => ‘new post’,
    ‘post_type’ => ‘proposal_entries’,
    ‘post_status’ => ‘publish’
    $post_id = wp_insert_post( $post_data );
    $ids = get_field(‘client’);
    $user_info = get_userdata($ids);
    $company = get_field(‘company_name’, ‘user_’. $ids);
    $number = get_field(‘contact_number’, ‘user_’. $ids );
    // Save a value for company
    $field_key = “field_601776e86bca8”;
    $value = $company ;
    update_field( $field_key, $value, $post_id );

    // Save a value for number
    $field_key = “field_60e307cb6c6f1z”;
    $value = $number;
    update_field( $field_key, $value, $post_id );

    update_field( $field_key, $value, $post_id );`

  • That might work, it’s hard for me to say with what you have provided.

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

You must be logged in to reply to this topic.