I am currently trying to create an autocomplete search with the element-api. I need results from two different elementTypes:
- Product::class
- Entry::class
How do I get results out of both elementTypes with only one endpoint?
Thats my working Product::class element-api.php config file:
return [
'endpoints' => [
'search.json' => function() {
// settings
$phrase = Craft::$app->request->getParam('query');
$criteria = [
'search' => 'title:'.$phrase,
];
return [
'elementType' => Product::class,
'criteria' => $criteria,
'paginate' => false,
'transformer' => function(Product $product) {
return [
'title' => $product->title,
'url' => $product->url,
];
},
];
},
]
];