Skip Navigation

[Resolved] Custom Post Type for Events + CRED: Check if max capacity is reached

This support ticket is created 6 years, 5 months ago. 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.

Author
Posts
#953853

Hi there,

I am extending my site to an event site where people should be able to signup for events using CRED forms.
However, each event has a maximum number of attendees set.

My structure:

Custom Post Type: Events
Custom Post Type: Leads
One Event can have many Leads.
To create Leads I have setup a CRED form.
In addition I have setup a custom field in Events: "max number of attendees" (number)

Is there any easy way to check if the number of Leads for a certain Event has reached the number of attendees?

Best
Bernhard

#953913

I have researched a bit in this forum and found a solution that seem to fit better:

Custom Post Type Events gets a "submission" field that increments with each cred form submission with the following code:

function.php (https://toolset.com/forums/topic/creating-a-booking-form/)

/**
 * 
 * Submission Count
 */
add_action('cred_save_data', 'cred_increment_submissions_action',10,2);
function cred_increment_submissions_action($post_id, $form_data)
{
    $forms = array( 367 );
    // if a specific form
    if (in_array($form_data['id'], $forms))
    {
        $eventid = $_POST['wpcf-event-id'];
        $count = get_post_meta( $eventid, 'wpcf-submission-count', true );
        update_post_meta( $eventid, 'wpcf-submission-count', $count+1 );
    }
}

Then, I have setup a field "max capacity" for Custom Post Type Events.
Via wpv-conditionals I have set the cred form to appear or dissappear.

If submission count is less than max-capacity: show form
if submission count is equal or above max-capacity: show text.

Best
Bernhard