I'm looking to get all entries from one section (say 'videos'), that are related to a specific category. The only reference to the category is the slug that is a parameter in the url:
....dev/videos/category-slug
I need to get the category id from the slug to be able to relate the videos to the category in the criteria:
'criteria' => [
'section' => 'videos',
'relatedTo' => ['targetElement' => $categoryId],
],
I can't seem to find a way to get the properties of the category before applying the criteria. Is there something on the EntriesService object that I can use to get the category entry, similar to template usage? E.g:
$categoryEntry = craft()->entries->section('categories')->slug('category-slug');
And then pass the $categoryEntry id through to the criteria to return all the related videos. E.g:
'criteria' => [
'section' => 'videos',
'relatedTo' => ['targetElement' => $categoryEntry->id],
],
Any help with a way I could do this all in one endpoint would be great. The alternative is passing the slug into another category endpoint to get the entry, then use the response to pass the id to the above endpoint.
Cheers!