Skip Navigation

[Closed] Create relationship between User and post using a proxy post type

This support ticket is created 4 years, 1 month 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 25 replies, has 2 voices.

Last updated by Christian Cox 4 years, 1 month ago.

Assisted by: Christian Cox.

Author
Posts
#1852791

I don't think I understand you

What do I have to change?

#1852795

You must change the value attribute. You currently have this:

value='Campaña Bonos Inicial'

You must use the parent post ID, not the parent post title. If the ID of the Campaña Bonos Inicial parent post is 12345, for example, the code must be changed to this:

 
value='12345'

You cannot use the parent post title in the value attribute, you must use the parent post ID.

#1852797
Captura de pantalla 2020-11-22 a las 20.16.10.png

with this code

<div class="form-group">
		<label>[cred_i18n name='@campana-bonos-bono.parent-label']Campaña[/cred_i18n]</label>
[cred_field field='@campana-bonos-bono.parent' class='form-control' output='bootstrap' select_text='--- not set ---' required='true' author='$current' value='5168' readonly='true']
	</div>

I cant select

#1852875

Well you shouldn't be able to use the select field on the front-end because you have set readonly="true". That makes the field unchangeable. However, the parent post should be visible in the select field when you set the value. I'd like to see what's happening. Can you provide a URL where I can see this on the site?

#1852877

Its here.

You need to be logged in

/form-bonos/

#1852893

It seems that the readonly attribute is causing the problem here. If I remove it, the field works as expected:

[cred_field field='@campana-bonos-bono.parent' class='form-control' output='bootstrap' select_text='--- not set ---' author='$current' value='5168']

I will keep investigating this to see if there is a problem in Forms or if I've misunderstood how the readonly attribute works in post relationship fields. For now, you could just hide the entire Campaña field on the front-end using CSS, since you want to set the value programmatically and not allow the User to edit it:

<div class="form-group" style="display:none !important;">
		<label>[cred_i18n name='@campana-bonos-bono.parent-label']Campaña[/cred_i18n]</label>
        [cred_field field='@campana-bonos-bono.parent' class='form-control' output='bootstrap' select_text='--- not set ---' author='$current' value='5168']
	</div>

Or you could set the relationship programmatically by removing the field entirely and using the toolset_connect_posts API in a cred_save_data callback:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
It would be arguably more secure this way.

#1852899

Thank you Cristhian

Is it possible that the date field is the current date on which the coupon is created?

#1852921

Yes, you can remove the date field from the Form and use custom code to set the value programmatically. The code is similar to an example I shared in another ticket:

add_action( 'cred_save_data', 'tssupp_auto_set_date_field_for_bono', 10, 2 );
function tssupp_auto_set_date_field_for_bono( $post_id, $form_data ) {
  $form_id = 12345; // your form ID
  $field_slug = 'your-date-field-slug';
  if ( $form_data['id'] == $form_id ) {
    update_post_meta( $post_id, 'wpcf-' . $field_slug, date('U') );
  }
}
#1853479

Thanks Cristhian,

This work fine. But how i cant modified custom type (ticket in other conversation) i cant continue with process.

#1853507

Okay I'm still investigating that issue and will give you an update shortly.

#1853569

Updated, let me know when you're ready to move forward here.

The topic ‘[Closed] Create relationship between User and post using a proxy post type’ is closed to new replies.