Skip Navigation

[Resolved] Put parent custom field value into child form field

This support ticket is created 4 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 8 replies, has 2 voices.

Last updated by marciW-2 4 years, 8 months ago.

Assisted by: Shane.

Author
Posts
#1797883

Tell us what you are trying to do?
I have a parent post type called Location. This has a one-to-many relationship with a child type called Traditional Office.
Both of these post types have a field called Property Address.
When using a form to create a new child (Traditional Office), I would like its Property Address value to automatically be the parent Property Address (Location). It's important that these fields match.

Is there any documentation that you are following?
https://toolset.com/forums/topic/cred-form-dynamic-default-value-based-on-post-custom-field/
This didn't work for me

Is there a similar example that we can see?

What is the link to your site?
hidden link

#1797997

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Marci,

Thank you for getting in touch.

Is this field an Address field ? Or is it a regular single line field that you typed the address in ?

Secondly are you navigating to the child post form from the Parent ?

If so can you let me know the URL parameter that gets added to the page that the child form is on ?

Thanks,
Shane

#1798015

Hi Shane,
Yes it's an address field.
And also yes, I am navigating to the child post from the parent. The url parameter is parent_location_id
Example:
hidden link

#1798069

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Marci,

For the field Value of your address field on the child form add this.
<Code>

[types field='address-field' item="[wpv-search-term param='parent_location_id']"]
[/php]

Replace address-field with the slug of your address field and this should pull the parent address into the child form.

Thanks,
Shane

#1798103

That didn't quite work as I need to be able to put this inside the value of the address field on the form.
If I just display the parent address outside of the address input it works, but it doesn't work inside of the input value.
Example:
hidden link

You can see the address outputted below here. I also have that code in the value of the Property Address but it doesn't work.

Code from the form:
<div class="form-group">
<label>Property Address</label>

[cred_field field="property-address" force_type="field" class="form-control" output="bootstrap" value='[types field="property-address" item="[wpv-search-term param='parent_location_id']"]']
</div>

[types field='property-address' item="[wpv-search-term param='parent_location_id']"]

#1798145

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Marci,

Please try doing it like this

[cred_field field="property-address" force_type="field" class="form-control" output="bootstrap" value="[types field='property-address' item='[wpv-search-term param='parent_location_id']']"]

If this doesn't work then we will need to wrap the code in some custom shortcode for it to work correctly.

Thanks,
Shane

#1798157

It didn't work. How can I wrap it in a shortcode?

#1800049

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Marci,

Try this now and it should work.


function get_value_from_url( $atts ) {

	// Attributes
	$atts = shortcode_atts(
		array(
			'url_att' => '',
		),
		$atts
	);

	$value = $_GET[$atts['url_att']];
	return do_shortcode("[types field='property-address' item='".$value."'][/types]");

}
add_shortcode( 'get_value_from_url', 'get_value_from_url' );

Add this custom shortcode to your custom code section in Toolset -> Settings -> Custom Code and activate it.

Now you can just do this once the shortcode is active.

[cred_field field="property-address" force_type="field" class="form-control" output="bootstrap" value="[get_value_from_url url_att='parent_location_id']"]

Please let me know if this helps now.
Thanks,
Shane

#1800861

My issue is resolved now. Thank you!