• Hi,

    I have a child theme setup, and I am using a calendar events plugin.

    I would like to use the data from https://localhost/wp/wp-json/tribe/events/v1/

    However, there are alot of fields I dont need. How can I remove them?

    Can I make a copy of the response and remove the fields somehow?

    Also, can I do this in my themes functions.php?

    Many thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter matthisco

    (@matthisco)

    I have tried to create a new endpoint by adding this to functions.php, by passing a parameter:

    function allow_compact_event( $data, $event, $request ) {
        // return compact data when _compact GET parameter exists 
        if(isset($_GET['_compact'])){
            return [
                'id'        => $data->data['id'],
                'title'     => $data->data['title']['rendered'],
                'link'      => $data->data['link'],
            ];
        }
        return $data;
    }
    
    add_filter( 'rest_prepare_event', 'allow_compact_event', 10, 3 );

    However, all the data comes down instead of the id, title, link. It doesn’t seem to work.

    Any ideas?

    • This reply was modified 7 years, 2 months ago by matthisco.
    Moderator bcworkz

    (@bcworkz)

    Go with the request that returns the data you need, even if it’s more than you need. The data returned is in JSON format. Use json_decode() on the returned data. This translates the data into a PHP array so you can easily address individual elements using conventional associative array references. You’ll likely want to initially print_r() the entire array after decoding in order to learn the proper array addressing to get to the data you want. Once you know the proper addressing, the print_r() can be removed.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Editing api response, where to start?’ is closed to new replies.