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
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.
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
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.
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)?
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!