Skip Navigation

[Resuelto] Register for Event

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:
How can I set a Post that is submitted with CRED, to be child to the Post, where the Form is inserted?
I also need to update it's title with a value coming from a Post Field

Solution:
You will use a Custom CRED API (cred_save_data) and Wordpress API (mainly get_ and update_post_meta) to achieve this

You will put the function created into your Theme's functions.php

In the Code, you will:
get_post_meta the field's value with which you want to update your Post title
wp_update_post the title with the above value

You must note that the parent post ID in this case will be the ID of the Post where you show the CRED, and this is stored in the CRED API $form_data['container_id'];

With this value you update the posts hidden field _wpcf_belongs_parent-post-slug_id

A good example is visible there:
http://pastebin.com/2BTbVbcs
https://toolset.com/forums/topic/register-for-event/page/2/#post-388619

Relevant Documentation:
https://toolset.com/documentation/user-guides/creating-cred-forms/
https://toolset.com/documentation/user-guides/cred-api/#csd
https://codex.wordpress.org/Child_Themes
https://codex.wordpress.org/Functions_File_Explained
https://codex.wordpress.org/WP_DEBUG

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

This topic contains 19 respuestas, has 2 mensajes.

Last updated by mirjanaM hace 8 años.

Assisted by: Beda.

Autor
Mensajes
#381898

Hi,

hope someone can help me with that.

I try to make something similar to an event site.

I make some Custom Post Types & also fields but now becomes to be a problem….

Under the EVENT there should be one simple Button, Radio Button or Dropdown for Registering for that Event. Like This…

Will you Register for that Event Yes/No ——> Sending Button.

- When the user Register for that event, they become a Waiting Status.
The Event Starter now can Accept or Decline the Registered User

I Think i must have more Post Types for that to work an then work with many-to-many-relationship

The Custom Post Type for Event is working but don't know where to start with that for registering user to that event with waiting status.

2. After the User is Accept for that event. He is unlocked and can Write Review for that event. Appears under that event.

I know that much, but i hope anyway someone can help me with that.

Regards Mirjana M.

#381937

The Button "Will you Register for that Event Yes/No ——> Sending Button." must be a CRED Form
https://toolset.com/documentation/user-guides/creating-cred-forms/

This CRED Form must create a new Post (registration)

The Registration Post type must be Child to Events.
https://toolset.com/documentation/user-guides/creating-post-type-relationships/

The CRED Form will hold only one Field (or more, nut hidden with <div class="hidden></div>) and the Submit Button.

The newly created Post ("Registration") will be set to published but with a specific Custom Field set by default as "not accepted".
https://toolset.com/documentation/user-guides/using-custom-fields/

This Field will help you to show all those "Registration" posts only according that Field Value in a View
(As example a view will show posts "Registration" where the custom field is "not accepted")

The next step is a CRED Edit Form for that same post type, where the Event Starter can edit the post and set it to "accepted"

After this the Registering user can see this post and also create more, let's say, chid posts "Review" so to write reviews for it as example.

You will need a small Custom Code snippet on the First CRED Form that creates the Registration.
This is to ensure the Registration is assigned to the Proper Event.

You will set the Registration post type to be child of Events and then apply this Code Snippet to your CRED Form with which you submit registrations:
https://toolset.com/documentation/user-guides/cred-api/#csd

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==12)
    {
        //get the Post ID of the current event:
       $event_id = $form_data['container_id'];
       //update the new registration post parent field with this ID:
       update_post_meta($post_id, '_wpcf_belongs_parent-post-type-slug_id', $event_id);
    }
}

This system you want to develop requires a bit of work, which seems at the first look overwhelming, but it is actually straight forward.

Let me know if you need more help with it.

Thank you

#382493

Hi Beda,

thank u so much for your fast help.
I have make a fresh start. And did all what you said but don't know where exactly to apply the code Snippet you gave me. I read the user guid but don't find anything.

Can you explain me ?

Thanks.

Mira

#382508

It has to be added to your Functions File functions.php

A theme can hold functionality, which is usually stored or better, coded in a plugin

All this codes are added to functions.php of your theme.

If you use a Commercial theme that will push updates, please first create a Child theme, otherwise, all changes will be dumped on any Update of your theme.

More info that might help you:
https://codex.wordpress.org/Child_Themes
https://codex.wordpress.org/Functions_File_Explained
https://codex.wordpress.org/WP_DEBUG

Please let me know any doubts or issues.

Thank you

#382581
Registrierungen ‹ testme24 — WordPress.png
Edit Testprodukt ‹ testme24 — WordPress.png
Edit Registrierung ‹ testme24 — WordPress.png

Ok. I have added this code now to my funktions.php (genesis theme).

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==45)
    {
        //get the Post ID of the current event:
       $testprodukt_id = $form_data['container_id'];
       //update the new registration post parent field with this ID:
       update_post_meta($post_id, '_wpcf_belongs_parent-post-type-slug_id', $testprodukt_id);
    }
}

I`ll post some screenshots. I think its not right what ill get there.

I become a draft, and its not auto save the right post (must chose).

Sorry for bothering you ;(

But many thanks for your patience.

#382614

I put the code in wrong functions.php. Now it get´s auto asign to the post. But still as auto draft.
How can I get it so its saved with the postname and with custom field´s like
[wpv-user field='nickname']
[wpv-user field='user_email']

or i still do something wrong ?

#382615

Mirjam, do you speak German? 🙂

Me too, if you want to proceed in German, no issue.

Let's see:

1. Post title is a Draft

That's most probably because the Title is either not present in the Post Edit Screen and / or the CRED form for "Registrations"

2. I understand the parent is not updated correctly?

We might address the wrong CRED Form. Did you adapt the Code as instructed in our DOC?
You must change a few things.

- The ID of the Form
- _wpcf_belongs_parent-post-type-slug_id
This is to adapt.
Your Post type (The parent) is surely not parent-post-type-slug.

Please change this accordingly.
(I see you seem to have changed the ID of the Form but not the slug of your POST TYPE parent-post-type-slug)

Let me know how that goes.

I assume you are working on a Test site?

Otherwise I strongly suggest to switch to one. It's easier and less dangerous to debug and construct things, in case I might need to login to help you.

Thank you

#382660

Hallo Beda,

super das du Deutsch sprichst 😉

Also ich versuch es jetzt mal auf dieser Sprache englisch lesen und verstehen ist kein Problem aber erklären eine Katastrophe.

- Der slug für mein Custom-Post-Type, für die Erstellung der sogenannten Events ist --- > testprodukt
- Der slug für mein Custom-Post-Type, für die Registrierungen bzw. Teilnahme --- > registrierung

Parent Post Types:
Select which post types will be parents of this type. -----> Testprodukt

CRED Form mit ID: 45

[credform class='cred-form cred-keep-original']

<div class="hidden">
[wpv-post-link]  
[wpv-user field='nickname']
[wpv-user field='user_email']
</div>

[cred_generic_field field='regist' type='select' class='' urlparam='']
{
"required":1,
"validate_format":1,
"persist":1,
"default":["1"],
"options":[
{"value":"1","label":"Ja"},
{"value":"2","label":"nein"}
]
}
[/cred_generic_field]


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

[cred_field field='form_messages' value='']

[/credform]

Und zu guter letzt der Code den ich in die Funktions eingesetzt habe...

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==45)
    {
        //get the Post ID of the current event:
       $event_id = $form_data['container_id'];
       //update the new registration post parent field with this ID:
       update_post_meta($post_id, '_wpcf_belongs_testprodukt_id', $event_id);
    }
}

Also wenn ich das jetzt so mache wie hier beschrieben. Wird es zwar gespeichert aber leider nur als "Auto Draft 837ec5754f503cfaaee0929fd48974e7".

Wichtig ist hier das ich noch zusätzliche Daten abfrage sonst kann ich das ja nicht zuordnen. Wie zum Beispiel Username & Email Adresse.

Beda, vielen dank für deine mühe & Hilfe 🙂

Lieben Gruß

Mira

ps.: Werde es morgen spätestens mal alles auf einem Server installieren, falls das immer noch nicht klappt das ich dir ein Zugang erstelle kann, da momentan alles Lokal läuft.

#384765

1. Du hast kein Titel in deiner CRED Form
WordPress interpretiert dies nicht und macht den Titel einfach (draft)+(Serien Nummer)

==> Entweder Du integrierst ein Titel in deine CRED Form oder Du aktualisierst diesen mit einer API Call Es Es kann im gleichen code wie Du bereits am entwickeln bist getan werden, nur adressieren wir hier auch noch post_title und post_name.
==> Beispiel hier:
http://pastebin.com/2BTbVbcs
(Der code nimmt ein Wert von einem Custom Field und adressiert damit den Titel und Slug des Posts)

2. Der code für Form 45 sieht jetzt gut aus.
Funktioniert er? Ich meine, ist der parent korrekt Gesetzt wenn Du eine Registrierung erstellst damit?

Eigentlich müsste nun die Form so Funktionieren:

1. Du integrierst die Form in den Post (Testprodukt) zu welchem die neue Registrierung gehören muss

2. Du schickst die Form ab:
- Der Code schnappt sich die ID des "Containers" (Welcher ja dein Testprodukt Post ist) und updated damit die neue Registrierung > Parent Post Field (_wpcf_belongs_testprodukt_id)

Bitte lass mich wissen wo's hapert.

Danke

#384985

Hi Beda,

hab das jetzt glaub in allen möglichen Varianten probiert. Weiterhin kein erfolg. Entweder bekomme ich ein Autodraft oder ein Post ohne Titel.

Gibt es eine Möglichkeit das ich dir die Login Daten mal zusende, das es dir Live anschaust?

Lieben Gruß

Mira

#385189

Also probiere das alles seit heute morgen und egal was und wie ich das machen es bleibt bei Autodraft. Oder wenn ich das so mache wie mit deinem letzten Code beschrieben, dann wird es gespeichert ohne Title.

Ausserdem ist noch die Frage aus meinen letzten beiträgen offen. Ausser dem Title, muss ich ja auch sehen können wer (welcher user) sich dafür registriert hat. Und das ist das gleiche wie mit dem Titel, wenn ich Felder in mein Formular einfüge die nicht zu dem Post_Type gehören, werden diese dort nicht angezeigt.

Hoffe du hast noch eine IDEE.

Wie schon vorgeschlagen, habe ich alles auf einem Server Online und könnte dir die Zugangsdaten hierzu geben.

Lg

Mirjana

#385258

Ich müsste um temporären WP Admin und FTP zugriff bitten
-vorzugsweise auf eine test Seite wo alle Probleme genau dupliziert wurden-
um effektiver helfen zu können und um zu überprüfen ob alle Konfigurationen korrekt sind

Ich werde die nächste Antwort als privat markieren, somit können nur Du und Ich zugriff auf die mitgeteilten Daten nehmen.

❌ Bitte erstelle ein komplettes Backup der Datenbasis und Website ❌

✙ Zusätzlich müsste ich die Erlaubnis haben, Plugins und Themes zu de- und re-aktivieren, sowie Konfigurationen zu ändern.
Deswegen währe das backup sehr wichtig falls Du mir zugriff auf die live-site gibst.

✙ Bitte erläutere genau wo Ich die Form, den Code, die Felder finde, und wie es funktionieren sollte.

✙ Ich werde Code editieren, dies kann ein crash verursachen, bitte mache en gutes Backup.

Danke

#386154

Könntest Du mir die benötigten Informationen zukommen lassen?
https://toolset.com/forums/topic/register-for-event/#post-385258

Da dies Custom Code ist, kann ich nicht zulange damit verbringen die Forms, Seiten und Code zu lokalisieren, sorry.

Ich sehe auch, deine Funktion adressiert form 10, aber diese Form hat kein Title Post Field, und der code updated diese auch nicht.

Ich habe zuvor ein Beispiel für diese Situation beigelegt:
https://toolset.com/forums/topic/register-for-event/#post-384765

Kannst Dum ir die benötigten Information zukommen lassen mit der genauen Beschreibung wie, wo und wann was passieren soll?

Dies scheint Zeitverschwendung, ist es aber nicht.

Wir liefern kein fertigen Custom Code ins forum und wenn wir damit helfen, sind wir 100% auf Zusammenarbeit angewiesen, da sonst andere anfragen welche Toolset Core features betreffen "warten" müssen.

Ich hoffe Du kannst dies verstehen.

Ich werde mir den code und Prozess anschauen sobald ich die genauen infos hab.

Danke vielmals fürs Verständnis und Zusammenarbeit.

#386227

Hallo Beda,

danke für deine Nachricht. Okay ich versuche alles so gut wie möglich zu erklären und zu beschreiben.

Ich habe das Custom Post Type Testprodukte erstellt und in dem das Custom Post Type Registrierungen.
Wenn jemand bei Testprodukte ein Post macht. Soll ein Registrierter User die Möglichkeit haben, sich für diesen zu Registrieren wie bei einem EVENT. Also im Prinzip muss man sich das ganze wie bei einem EVENT vorstellen.
Einer Postet ein Event und der User kann sich dafür Registrieren.

Was für mich Wichtig ist:

Ich muss den Post Registrierungen zuweisen können. Das heisst ich benötige Felder die der Kunde der ja Registriert ist mit seinem Klick auf JA bestätigt.Also...

- Title zu welchem Post hat sich der User Registriert
- Username des Registrierten
- Email des Users

-----------------------

Den ersten code https://toolset.com/forums/topic/register-for-event/#post-381937, habe ich Probiert (ist Aktuell noch drinn), der Funktioniert in sofern das er den Post richtig zuweisen tut. Aber es bleibt auf Autodraft.

Den zweiten Code habe ich auch versucht https://toolset.com/forums/topic/register-for-event/#post-384765. Allerdings bekomme ich nun (no title). Deswegen hatte ich den Code wieder aus der Funktions.php entfernt.

In der Form: 10 habe ich 2 Titel eingefügt...

[types field="produkt-titel"][/types]
[wpv-post-title]

[types field="produkt-titel"][/types] ist im Post Field Groups <Produktbeschreibung> und gehört zu <Testprodukt> (Im prinzip ein zweiter TITLE)

[wpv-post-title] ist der Standart Post Title

Oder habe ich das mit dem Title falsch verstanden ?

Reicht das als Information ?

#388023

Okay,...for 3 day´s now i try to fix this.

Tryed difrent solutions from other users in this Forum. But nothing, sure i make something wrong. But what ?

I know you cant do this for me, but this can not be so hard to get a title in there.

AUTO DRAFT with this code...

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==45)
    {
        //get the Post ID of the current event:
       $event_id = $form_data['container_id'];
       //update the new registration post parent field with this ID:
       update_post_meta($post_id, '_wpcf_belongs_testprodukt_id', $event_id);
    }
}

NO TITLE with this...

function my_action($post_id, $form_data){
            // Change your CRED Form "ID" accordingly below
            if ($form_data['id']==45){
               
                //Declare the content of your variables, change "your_custom_field_slug" accordingly
                $custom_title = get_post_meta( $post_id, 'wpcf-produkt-title', true );
               
                //collect data and define new title
                $my_post = array(
                    'ID'               => $post_id,
                    'post_title'   => $custom_title,
                    'post_name' => $custom_title,
                   
                );
               
                // Update the post into the database
                wp_update_post( $my_post );
               
            }
        }
		add_action('cred_save_data', 'my_action',10,2);

and also no Title with this...

function set_registrierung_title_func($post_id) {
    if ( wp_is_post_revision( $post_id ) || get_post_type($post_id) != 'registrierung') 
        return;
      
    $update_args['ID'] = $post_id;
    $update_args['post_title'] = get_post_meta($post_id, 'wpcf-produkt-title', true);
    remove_action('save_post', 'set_registrierung_title_func', 99);
    $res = wp_update_post( $update_args );
    // re-hook this function
    add_action('save_post', 'set_registrierung_title_func', 99);
}
add_action( 'save_post', 'set_registrierung_title_func', 99 );    

Also tryed many other things.

You sayd i have not set up a Title in CRED. Ok, but how i do that?
I have put post-title in all Forms and it shows up i fronend.

I there no tutorial for something like that ?

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