Use external API data in Query Loop

Hi all,

I’m trying to use API data (from Ticket Tailor) in a query loop.

The API is working and I can render data from it into pages, however I can’t seem to get it working with the query loop. The issue is that my dynamic data always renders as plain text on the frontend. It does have the right amount of entries/loops (2) but no rendered content.

I’ve tried creating some test data to debug this but get the same result with that. I’m sure I’m missing something obvious here, please help!

Test -

add_filter("bricks/setup/control_options", function($options) {
    $options["queryTypes"]["my_fake_query"] = "My Fake Query";
    return $options;
});

add_filter("bricks/query/run", function($results, $query_obj) {
    if ($query_obj->object_type !== "my_fake_query") return $results;

    $fake_data = [
        ['id' => 1, 'name' => 'Event A'],
        ['id' => 2, 'name' => 'Event B'],
    ];

    $loop_items = [];
    foreach ($fake_data as $item) {
        $obj = (object)$item;
        $obj->ID         = $obj->id;
        $obj->post_title = $obj->name;
        $loop_items[]    = $obj;
    }
    return $loop_items;
}, 20, 2);

Thanks very much!

1 Like

Hi did you figure this out or talk to support about how to handle this issue?

PS - I would love a new “From API” option in the query loop builder… Starting with the WP REST API of course!

Hi @ddcbf, I’m afraid I didn’t figure out how to do it using native Bricks query loop.

I ended up using some js to map the events from the API. I built how I wanted each event to look in Bricks, using a class for each element, so that when I mapped the events the it was already styled with those classes. This way when I want to make an adjustment to the styling I can do that using the Bricks class rather than css, which is a little nicer.

It’s on their roadmap as ‘in progress’

3 Likes