Skip Navigation

[Geschlossen] how to save child post with cred ?

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 support ticket is created vor 10 Jahre, 10 Monate. 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
- 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 -
- - - - - - -

Supporter timezone: Europe/Madrid (GMT+01:00)

This topic contains 12 Antworten, has 2 Stimmen.

Last updated by Caridad vor 10 Jahre, 9 Monate.

Assisted by: Caridad.

Author
Artikel
#104580

Hello I'm starting to look at using CRED or gravity forms? but i cant see why CRED does not allow me to choose the child posts

I have created the many to many relationship here and i want to add the - 'Bands' to the Event, along with the parent Venue.

hidden link

But i cant see how this is to work.. any tips please?

#105006

Dear Steve,

A many-to-many relationship is not the same as a parent-child relationship. For the many-to-many relationship you have to set the relation with some code attached to the cred_save_data filter. There are more details here:

https://toolset.com/documentation/user-guides/cred-api/

You will need to create a record in the intermediary table and save a _wpcf_belongs_xxxxx_id for each of its parents.

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

Regards,
Caridad

#105050

Ah, OK that does sound a little tricky i must admit, any chance of example relating to what i have setup so far ?.

It would be great if the wizard for the form did this for me, but then i guess i'm asking too much 🙂

is al this also possible with Gravity forms? .. I only ask as i have many gravity forms setup

#105310

Dear Steve,

We have 3 custom post types, lets call them "band", "event" and "bandevent". I assume that the bands are already created and you are going to submit a form to create an event. You will a code like the following in functions.php of your theme:

add_filter( 'cred_save_data', 'cred_save_event', 10, 2 );
function cred_save_event( $post_id, $form_data ) {
  if ( $form_data['id'] == 23 ) {
    // save a record to the intermediary table
    $id = wp_insert_post(array( 'post_status' => 'publish', 'post_type' => 'bandevent' ));
    // set the event as parent
    update_post_meta( $id, '_wpcf_belongs_event_id', $post_id );
    // set the band as parent
    update_post_meta( $id, '_wpcf_belongs_band_id', $_POST['band_id'] );
  }
}

Two remarks about this code:

1) You need to replace 23 with the form id that you are trying to intercept.

2) You need to somehow provide the id of the band so we can relate it. I used $_POST['band_id'] but you will need to adjust this to your situation.

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

Regards,
Caridad

#105313

Ok thanks that's starting to make sense now

but the event has Many Bands playing .. is it possible just to have a drop down that list all the bands, so many can assigned?

in fact i have 4 CPT going on Luio advise . .. we setup 'Bands' 'Venues' 'Events' and 'my-intermediaries'

does this change how i would do it? .. you can see the relationships we setup in the demo site if that helps.. hidden link

#105689

Dear Steve,

It is possible to do this, to start create a multiple select dropdown with bands (or checkboxes) and in the cred_save_data hook loop through the bands creating one record in the intermediary table for each band that you want to add to the event.

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

Regards,
Caridad

#110033

You make ti sound so easy! 🙂

how exactly do i do this please?.. this is the final step i need to complete my site, Views and CRED have been great i'm very happy i purchased the toolset.

i have post types: venue, events, bands, my-intermediaries

I have auto generated my CRED create event form.

I have added the multi select drop down for the band selection , but i have no idea how to populate it with the bands

then final part would be setting the Venue parent.

Big thanks in advanced.

#110844

Dear Steve,

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

Regards,
Caridad

#110845

??? missing answer?

#110859

Dear Steve,

What code are you using to display the multiselect drop down?

Regards,
Caridad

#110862

ok this is as far as i have got the last bit of my form:

	<div class="cred-group cred-group-parents">
		<div class="cred-field cred-field-_wpcf_belongs_venue_id">
			<div class="cred-label">add bands to event line up</div>
      [cred_generic_field field="band" type="multiselect" class="" urlparam=""]
{
"required":0,
"validate_format":0,
"persist":0,
"default":[],
"options":[ band ]
}
[/cred_generic_field]

          	</div>
      
		<div class="cred-field cred-field-post_parent">
			<div class="cred-label">add the Venue</div>
			[cred_field field="post_parent" value="venue"]
		</div>
		
	</div>

	[cred_field field="form_submit" value="Submit" urlparam=""]

[/credform]

#111400

any ideas? 🙂

#112013

Dear Steve,

Generic fields aren't saved automatically to the database and you need to add specific code in the cred_data_save hook to store the information:
https://toolset.com/documentation/user-guides/cred-api/

Can you try using a post field instead?
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred-field

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

Regards,
Caridad

Das Thema „[Geschlossen] how to save child post with cred ?“ ist für neue Antworten geschlossen.