Autofill ACF Fields | WordPress.org

[ad_1]

Hi @iceman3333,

I’m afraid, there isn’t any out-of-the-box setting for such a workflow. However, this should be possible using custom code.

I’m checking with our developer regarding this to see if we could provide a workaround.

Will keep you posted once we get further feedback asap.

Kind Regards,

Nithin

Hi @iceman3333,

Could you please try this snippet and see whether it helps:

<?php

add_action( 'forminator_before_form_render', 'wpmudev_number_field_value_form', 10, 5 );
function wpmudev_number_field_value_form( $id, $form_type, $post_id, $form_fields, $form_settings ) {
	if ( 943 == $id ) {
		add_filter( 'forminator_field_number_markup', 'wpmudev_add_value_field_cpt', 10, 5 );
	}
}

function wpmudev_add_value_field_cpt( $html, $id, $required, $placeholder, $value ) {
	$meta_val="";
	if ( strpos( $id, 'forminator-field-number-1' ) !== false ) {
		$meta_val = get_post_meta( get_the_ID(), 'member_number', true );
		$html = str_replace( 'name="number-1"', 'name="number-1" value="'.$meta_val.'"', $html );
	}
	
	return $html;
}

The above snippet is only meant to auto fill a Number field in the form with an ACF field.

Where 943 in the above code is a form ID and would recommend you to replace that with your form ID.

In the given code, the number-1 should be changed to your Number fields ID in your form. The member_number in above code needs to be replaced with the ACF custom field name.

You can apply the above code as a mu-plugins. Please check this link on how to implement the above code as a mu-plugins:
https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

Kind Regards,

Nithin
`

Thanks for the help, thought this might be easier. I have to find a simpler solution.

You can close the request

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer