Skip Navigation

[Resuelto] Cred Form Adds New 'Event' Post Type, User Links Existing/New Child Post

This support ticket is created hace 8 años, 2 meses. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Etiquetado: 

This topic contains 7 respuestas, has 3 mensajes.

Last updated by Beda hace 8 años, 1 mes.

Assisted by: Beda.

Autor
Mensajes
#373193

I am creating a city ecommerce website which introduces lots of info about a city, and lets users submit information.

This post deals with 4 custom post types -> Events, Listings, Organizers, and Products, in which Events is the parent of the others.

I would like to allow a user to use cred to add a new event and then link listings (venue/place), organizers, and products (tickets) to the event. Here's how the workflow would work (at least in my mind and after lots of searching and reading).

Step 1. -> User Creates "Event" with Post ID = event_id

Notes:
*User is owner of event

Step 2. -> User can select from list of existing (all) OR add new "Listing" -> wpcf_belongs_event_id = eventid from step 1

Notes:
*Not sure how to display list of existing Post Titles and update their link to Parent.
*I do not want user to "own" this post. If they select it from a list, owner doesn't change. If they create new post, owner is site admin.

Step 3. -> User can select from list of existing (only ones user has created) OR add new "Organizer" -> wpcf_belongs_event_id = eventid from step 1

Notes:
*Not sure how to display list of existing Post Titles (that user has created) and update their link to Parent.
*User can own this post!

Step 4. -> User creates "Product" (a woocommerce product) -> wpcf_belongs_event_id = eventid from step 1

Notes:
*This should be a repeatable field in which user can create a couple different products, each with different prices.
*User is owner of product(s)
_________________________________________

*I realize that I could create 4 separate cred forms, one for event, and three child forms for each CPT that links to that event post id, as explained here: https://toolset.com/forums/topic/parent-created-wcred-pass-parent-id-to-child-_wpcf_belongs_parent_id-value/

But how can I let the user choose a child post that already exists OR let him/her create a new post?

**Bonus Points: How can I combine this all into one CRED form instead of 4? I saw that it is possible to do this using "insert_post", I think, but I lost the link to that.

***Bonus Points 2: Do I need to create a new form if the user wants to edit these?

Thanks!

#373198

I am interested in this too

#373373

I apologize the delay here

1. I would like to allow a user to use cred to add a new event and then link listings (venue/place), organizers, and products (tickets) to the event.

Using CRED this is not possible from within the parent post type, but only from within the Child Post Type

Also in the WordPress Admin Screen you will only be able to add Child Posts, not to link existing Posts (Child type) to the currently edited Parent.

Only from within the Child Post Type scenes you can link parents.

2. The CRED Form allows you to create Child posts to a given parent with the CRED Create Child Post Link, which you can see how to use here:
https://toolset.com/documentation/user-guides/cred-forms-for-child-content/

3. Every CRED form is assigned to a Post type and a action (edit/create)
There is no way to change this, also not programmatically, unless you apply Custom Actions with CRED API code, which would eventually update a Post after submit, but this is not a EDIT and CREATE form in the same, or even a Form that edits/creates 2 posts types simultaneously.

4. You can create a List of Posts with Views (Child Posts) and populate a (example) DropDown/Select Field in CRED with this.
You will need to produce a valid JSON output and Views is not the designated tool to do this, but you can, if you carefully pay attention to the syntax and use the below linked custom Filter.
https://toolset.com/forums/topic/views-result-array-as-shortcode-parameter/page/3/#post-345627

This would then be inserted to the CRED Form (as a select field) with which you generate / edit your Parent Post.

When the user submits the form with, a Custom CRED API code runs, and gets the ID from the post the user chose to be child to the currently edited/created Parent post, and then updates that Child Post's _wpcf_belongs_post-type_id field with the ID of the currently edited / created Post.

Note that this will create confusion and problems, since another user will be able to do the same, but each Child Post can ONLY hold one such value for the _wpcf_belongs_post-type_id
https://toolset.com/documentation/user-guides/creating-post-type-relationships/

Therefore additional code would be needed to exclude all Posts that already store a parent ID.

Or, you would need the recommended approach of using the Create Child Link as mentioned above in this thread.

Please let me know if you have further questions regarding the issue mentioned in this Thread

Thank you for your patience.

#373393

OK. Thanks, Beda. That was actually pretty difficult to understand. This is what I got out of the last message:

*It's best to create 4 forms, one for each CPT that I need to make for an event.

*Once an event is created with the first form, I can have the user finish creating the other Child Post Types by putting the remaining CRED Child Post forms in the Events View under the sections they belong to (e.g. Venue, Organizer, Tickets).

*For #4 with the select/dropdown box, I'll take a look at the forum post, but didn't quite understand. If each child post can only belong to one parent, then that isn't the best solution for me. I would like a single venue (listing) and organizer to be able to hold multiple events. (for example, the Park holds events every Sunday, or XX Club has these events: xxx). When the user is managing his/her event and filling out the sections, how would they be able to add an existing child post to their event data, or add a new one if it doesn't already exist? Once a listing / organizer is added to an event, not only would the single event page show that information, but the listing and organizer pages would also show which events are "connected". I think this seems to be the toughest part.

#373398

One more question: What if instead of making "Events" the parent of Listings, Organizers, and Products, I made Listings AND Organizers the parent of Events, and Products the child of Events? After all, each event would only be used once, Listings and Organizers could have multiple Events, and Events could have multiple Products (tickets)... Is my logic correct here?

#373659

You last approach is achievable since Types allows a parent to have many child of the same type but not vice versa.

Also, you could then choose the Parent when editing / creating the Child

The other approaches involve Custom Code, non suggested ways to create JSON outputs.

The Workflow is then:
- user creates parent posts (Listings AND Organizers)
- user creates Child Posts (Events) with the Create Child Post Link
- user creates Childs of Events (Products) again with the Child Post Link

If this fits also your display goal it will work.

You will then as example query Events and display parents of the post in the View, and a second view which displays Products that are child of the Post set by the parent view, helps you display the related products, if that view is inserted to the Events View.

Please let me know if you have further questions regarding the issue mentioned in this Thread

Thank you for your patience.

#374212

Great, Beda. I'm doing it a bit differently than from what you described. The user creates the child post 'Events' first and then is directed to the single-event page in which the forms for selecting an existing or creating a new Listing (Venue) / Organizer are located. This page also has a section to add tickets.

1. The 'select an existing' Listing / Organizer forms are just CRED edit post forms which edit the 'Events" CPT, with only the '_wpcf_belongs_listing_id' / '_wpcf_belongs_organizer_id' field displayed as an autofill or select box. One form for each.

2. The 'create a new' Listing / Organizer forms are CRED create post forms for the Listing / Organizer CPTs, respectively. One a new post is created, the user stays on the Event page and then has to select the Listing / Organizer they've just created from the forms described in #1.

3. The tickets form was the most difficult because it requires CRED API hooks to set both a. the parent of the ticket(s) as Events, b. and the category of the product created (ticket) as 'Ticket'.

a. To set the parent of each ticket created as 'Event' on form '154', use this hook in functions.php:

//*Tickets automatically linked to Event with CRED
function my_save_data_action($post_id, $form_data)
{
    // if a specific form, change ID to the CRED "Review" ID
    if ($form_data['id']==154)
    {
        //get current post/page ID (where CRED is inserted to) - for CRED forms on Child Posts
        $current_post_ID = $form_data["container_id"];
        //Update the _wpcf_belongs_business-listing_id field of newly created Post
        update_post_meta($post_id, '_wpcf_belongs_event_id', $current_post_ID);
    }
}

b. To set the category 'product_cat' each ticket created as 'tickets' on form '154', use this code:

//*Save Event Tickets with 'Tickets' Taxonomy
add_action('cred_save_data', 'my_save_data_action_2',10,2);
function my_save_data_action_2($post_id, $form_data)
{
    // If a specific form
    if ($form_data['id']==154)
    {
		$my_taxonomy = 'product_cat';
		$term_list = array('tickets');
		wp_set_object_terms( $post_id, $term_list, $my_taxonomy );
	}
}

I'm using layouts, and views on my Events Single Page, which updates the Organizer, Venue, and Tickets created right after the submit button is pressed. If any one of the fields are not complete, conditional text statements appear to remind the user to add them in, which disappear and are replaced with information when it is added.

I will post all of this later, when I get it to look nice.

#374303

Cool. Keep us posted.

Any doubt or question I'm here.

Thank you

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