Canton

Forum Replies Created

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • Canton
    Participant

    I solved this. The REST documentation only mentions tribe_rest_single_event_data, which is only good for modifying the output from getting the output from a single event.

    I dug through the source code and discovered the tribe_rest_event_data filter, which is what modifies the output of the more general /wp-json/tribe/events/v1/events endpoint.

    May I recommend that the documentation be updated to include a list of all the available filters? (Or at least more than just the single filter?)

    For anyone who’s looking for a way to add the custom fields to the multi-event REST output, here’s sample code for your functions.php file. Note the commented out line that lets you discover what mysterious _ecp_custom_x meta name was assigned for each of your custom fields.

    add_filter( ‘tribe_rest_event_data’, ‘api_add_custom_values_all’ );

    function api_add_custom_values_all( array $event_data ) {
    // $meta = get_post_meta($event_id); print_r($meta); exit; // use this to figure out custom field names e.g. _ecp_custom_2
    $event_id = $event_data[‘id’];
    $max_participants = get_post_meta( $event_id, ‘_ecp_custom_3’, true );
    $event_data[‘max_participants’] = $max_participants;
    $attendance = get_post_meta( $event_id, ‘_ecp_custom_2’, true );
    $event_data[‘attendance’] = $attendance;
    return $event_data;
    }

    Canton
    Participant

    Worked great, thanks: https://www.dropbox.com/s/uj2l06uf0g5kclx/Screenshot%202015-10-16%2014.39.04.png?dl=0

    Note: Your trouble ticket emailing system mangled up your search/replace code some. I figured it out anyway, but I figure you might want to know that your emailing system is unnecessarily HTML-entitying in some cases:

    https://www.dropbox.com/s/6s2cjy8yhw1rgng/Screenshot%202015-10-16%2014.39.37.png?dl=0

Viewing 2 posts - 1 through 2 (of 2 total)