Events Made Easy Forums How do I … Calculate number of bookings with custom field equal to a certain value

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #62462
    Anonymous
    Inactive

    Hi,

    I would like to count which approved bookings have a custom field (cf) set to A, B or C.

    For example I would like to generate a page with this list:

    cf | number of bookings
    ————————–
    A | 31
    B | 41
    C | 59

    I tried using eme_get_event_cf_answers(), but print_r() didn’t return anything useful.

    How would one go about getting custom fields data out of EME?

    Thanks in advance for any help!

    #62463
    Franky
    Keymaster

    You need to call “eme_get_booking_answers($booking_id)” per booking id.

    #62464
    Anonymous
    Inactive

    Thanks for your response.

    I tried this:

    $booking_id = 135;
    $answers = eme_get_booking_answers($booking_id);
    var_dump($answers);

    But this prints: array(0).

    I don’t know what else to do, I can’t find anything about this in the documentation.

    #62465
    Anonymous
    Inactive

    I’m using fields from: eme-formfields if that matters.

    #62466
    Anonymous
    Inactive

    Found this post containing the function declaration of eme_get_booking_answers():

    function eme_get_booking_answers($booking_id) {
       global $wpdb;
       $answers_table = $wpdb->prefix.ANSWERS_TBNAME; 
       $sql = $wpdb->prepare("SELECT * FROM $answers_table WHERE booking_id=%d",$booking_id);
       return $wpdb->get_results($sql, ARRAY_A);
    }

    I looked up the table wpea_eme_answers, where I see that for some reason the booking_id column is 0 for all rows. Instead the person_id seems to be coupled to the form fields. Using the eme_get_booking_answers() with the booking_id seems to be the wrong way to get the data out of EME in my case.

    Is there another function that I can use to achieve my goal? Seems difficult, as I’d have to get what person IDs have an approved booking in my event, and then find their answer.

    #62467
    Franky
    Keymaster

    If the fields you defined are not RSVP-fields but person-fields, then they will be related to the person and not the booking. In that case, you can get the person id out of the $booking array and get all person-related custom fields like this:
    $answers = eme_get_person_answers($booking['person_id']);

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘How do I …’ is closed to new topics and replies.
Scroll to Top