Skip Navigation

[Resolved] Auto assign many-to-many relationship to a parent

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.

This thread is resolved. Here is a description of the problem and solution.

Problem: I have a CRED form that allows users to create child posts. I would like to predefine the parent post so the User does not need to select it.

Solution: If you want to predefine values for a CRED field, you have 3 basic options:

1. Provide the value as a URL parameter. Link to the page containing the CRED form using the URL value to supply the correct parent ID, something like yoursite.com/cred-form-page?contatti=1234. Then update your parent contatti CRED field and add the urlparam attribute:

[cred_field field='_wpcf_belongs_contatti_id' post="iscrizioni" urlparam="contatti"]

This would predefine the contatti with ID 1234 as the parent of the new post.

2. Provide the value in the value attribute. You can use a hard-coded number or a shortcode in the value attribute to predefine the parent contatti ID:

[cred_field field='_wpcf_belongs_contatti_id' post="iscrizioni" value="1234"]

3. Write your own custom code with JavaScript and/or PHP. Note that there is no CRED JavaScript API, so the amount of support we can provide for custom JavaScript is fairly limited.

In all 3 cases, you can wrap the field in a hidden div if you want to hide the field from your Users:

<div style="display:none;">
[cred_field ...]
</div>

Relevant Documentation:
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_field

This support ticket is created 6 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

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 5 replies, has 2 voices.

Last updated by Christian Cox 6 years, 2 months ago.

Assisted by: Christian Cox.

Author
Posts
#604364
Immagine.jpg

Hello i'm using many to many relationships. I have post type "iscrizioni" child of "contatti" and "corsi". I'm using CRED to input.
Here is my example page:
hidden link

Clicking on tab "ISCRIZIONI" and then on button "AGGIUNGI ISCRIZIONE" we can add post type "iscrizioni".

We can choose correctly parent "corsi" and contatti.

I would auto assign to current contact, we don't need to specify again because we are already in contact tabs. In backend i could add a new "iscrizione" from "contatto" correctly, i have problem only with CRED.

It is possible?

Thanks

#604481

Hi, if you want to predefine values for a CRED field, you have 3 basic options:

1. Provide the value as a URL parameter. Link to the page containing the CRED form using the URL value to supply the correct parent ID, something like yoursite.com/cred-form-page?contatti=1234. Then update your parent contatti CRED field and add the urlparam attribute:

[cred_field field='_wpcf_belongs_contatti_id' post="iscrizioni" urlparam="contatti"]

This would predefine the contatti with ID 1234 as the parent of the new post.

2. Provide the value in the value attribute. You can use a hard-coded number or a shortcode in the value attribute to predefine the parent contatti ID:

[cred_field field='_wpcf_belongs_contatti_id' post="iscrizioni" value="1234"]

3. Write your own custom code with JavaScript and/or PHP. Note that there is no CRED JavaScript API, so the amount of support we can provide for custom JavaScript is fairly limited.

In all 3 cases, you can wrap the field in a hidden div if you want to hide the field from your Users:

<div style="display:none;">
[cred_field ...]
</div>

The documentation for CRED fields can be found here:
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_field
Click the orange "More" button to see some examples.

#604490
Immaginecred.jpg

Hello and thanks for response. I think i explained bad myself. The value in not the same in every form, i would to get from parent "contatto".

I don't understand if I am doing wrong with post relationship logic.

If in backend i edit "contatto-jack" and add "iscrizione-425" is obviously assigned to jack.

I'm trying to do the same with cred

#604543

The value in not the same in every form, i would to get from parent "contatto".
I think you explained very well. I believe I am able to understand what you want to accomplish. You would like to use a CRED form to create a child post ("iscrizione" post type) for a specific parent post ("contatto" post type). The parent contatto will not always be the same, it will be dynamic.

In your CRED form, there is a field that allows the user to select a parent contatti for the new iscrizione post. This field will look something like this when you create the form:

[cred_field field='_wpcf_belongs_contatti_id' post='iscrizioni' value='' class='form-control' output='bootstrap']

The "value" of this field will determine the parent contatti. To predefine a parent contatti post in the CRED form, you must use one of the 3 methods I described. You must use a URL parameter to capture the parent ID, or pass the parent contatti ID into the cred_field using the "value" attribute, or use custom code.

You must decide which of these 3 methods works best for your site.

#604569

Thanks Christian you are right i managed via shortcode ID (finally!)

Cred shortcode used:

[cred_field field='_wpcf_belongs_contatto_id' post='iscrizione' value='[wpv-post-id id="$contatto"]' class='form-control' output='bootstrap']

I would a couple of questions:
I undestood that for me would be better simply add repeating group fields to my "contatto" custom post

With toolset and cred what is better method (database point of view also)?

#604573

Please create a new ticket for each additional question. We try to limit each ticket to one specific topic. Thanks for helping us keep the forum organized!

The forum ‘Types Community Support’ is closed to new topics and replies.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.