Support

Account

Home Forums Backend Issues (wp-admin) Lookups: how to use a Select to update other fields? Reply To: Lookups: how to use a Select to update other fields?

  • As mentioned above, it depends on how you store the venue data.

    If you can dynamically populate the select, set the value as the venue ID
    Then set the option label as the address

    You could then use the acf/save_post hook for when the form is triggered, something like:

    function my_acf_save_post( $post_id ) {
    
        // Get newly saved values.
        $values = get_fields( $post_id );
    
        // Check the new value of a specific field.
        $select_field = get_field_object('select_field', $post_id);
    	
    	//we now have the post ID of the venue
    	$venue_id = $select_field['value'];
    	
        if( $venue_id ) {
    
    		$address_line_1 = get_post_meta( $venue_id , 'address_line_1', true );
    		update_post_meta( $post_id, 'address_line_1', $address_line_1 );
    		
    		#repeat for other address fields
    		
        }
    }
    #acf/save_post action after ACF has saved the $_POST data. This is possible by using a priority greater  than 1.
    add_action('acf/save_post', 'my_acf_save_post', 20);

    So when then form is triggered, you get can then get the venue ID

    Once you have this, you can get the various address elements and update the post populating the various address fields.

    Just a thought! Trying to go the Ajax route may be a headache