Events Made Easy › Forums › How do I … › Calculate number of bookings with custom field equal to a certain value
- This topic has 5 replies, 2 voices, and was last updated 5 years, 1 month ago by
Franky.
-
AuthorPosts
-
Sun 11 Apr 2021 at 03:16 #62462
Anonymous
InactiveHi,
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 | 59I 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!
Sun 11 Apr 2021 at 14:31 #62463Franky
KeymasterYou need to call “eme_get_booking_answers($booking_id)” per booking id.
Sun 11 Apr 2021 at 20:53 #62464Anonymous
InactiveThanks 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.
Sun 11 Apr 2021 at 21:08 #62465Anonymous
InactiveI’m using fields from:
eme-formfieldsif that matters.Sun 11 Apr 2021 at 22:27 #62466Anonymous
InactiveFound 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 thebooking_idcolumn is0for all rows. Instead theperson_idseems to be coupled to the form fields. Using theeme_get_booking_answers()with thebooking_idseems 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.
Sun 11 Apr 2021 at 23:06 #62467Franky
KeymasterIf 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']); -
AuthorPosts
- The forum ‘How do I …’ is closed to new topics and replies.