document how to add craft singles to index #360
-
Is there a way to add Craft 'singles' to an algolia index? Did I miss this in the documentation? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Hey @npegman Adding singles works the same as any other section - Craft allows us to pass an array of handles to Then in your transformer you can check the element's section and parse the fields per section/single/channel Does that help? |
Beta Was this translation helpful? Give feedback.
-
There's no way to do it dynamically? I knew about the hardcoded method you describe above but trying to avoid it to eliminate the need to have to add/remove new singles. Craft must have some means of querying for all singles as they list them in the cp. |
Beta Was this translation helpful? Give feedback.
-
You can of course query all singles, parse those and pass them to the query. For example (for Craft 5): $sections = Craft::$app->getEntries()->getSectionsByType('single');
$handles = collect($sections)->map(function ($section) {
return $section->handle;
})->toArray();
query->section($handles); You can of course then also merge that array with a different one of different sections |
Beta Was this translation helpful? Give feedback.
You can of course query all singles, parse those and pass them to the query. For example (for Craft 5):
You can of course then also merge that array with a different one of different sections