Support

Account

Home Forums Front-end Issues ACF_Form

Helping

ACF_Form

  • Hi Guys,

    I have a custom post type called ‘submissions’ where it has the following fields:

    • Post Title
    • Custom Field: user_id
    • Custom Field: teacher
    • Custom Field: sorness

    As it is, the form is setup to show only the soreness input field where ‘user_id’ and ‘teacher’ custom fields are hidden, however, I would like to populate these (user_id, teacher) with current data from the logged in user.

    The custom field ‘user_id’ would be $current_user->ID and teacher would be another stored variable.

    I assume this would be set inside ‘new_post’ array? Can somebody please help?

    <?php
    
    acf_form(array(
    	'post_id'			=> 'new_post',
    	'post_title'		=> false,
    	'post_content'		=> false,
    	'fields' 			=> array(
    		'soreness'
    	),
    	'new_post'			=> array(
    		'post_type'		=> 'submissions',
    		'post_status'	=> 'publish',
    		'post_title'	=> $current_user->user_login,
    		),
    		'submit_value'	=> 'Send'
    	));
    
    ?>

    Cheers

    Tim

  • Hi @tebrown

    I would use the acf/save_post action as found here: https://www.advancedcustomfields.com/resources/using-acf_form-to-create-a-new-post/

    You can get the current user via the get_current_user_id as found here: https://developer.wordpress.org/reference/functions/get_current_user_id/

    I hope this helps.

    Phil

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

The topic ‘ACF_Form’ is closed to new replies.