- This topic has 5 replies, 2 voices, and was last updated 3 years, 7 months ago by .
Viewing 6 posts - 1 through 6 (of 6 total)
Viewing 6 posts - 1 through 6 (of 6 total)
- The forum ‘How do I …’ is closed to new topics and replies.
Events Made Easy › Forums › How do I … › Calculate number of bookings with custom field equal to a certain value
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!
You need to call “eme_get_booking_answers($booking_id)” per booking id.
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.
I’m using fields from: eme-formfields
if that matters.
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.
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']);