Guest User

Untitled

a guest
Jun 25th, 2019
51
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'api/custom-endpoint.json' => function() {
  2.  
  3. $tagSlugs = array('tag-one', 'tag-two');
  4. $tagIds = Tag::find()->group('tagGroup')->slug($tagSlugs)->ids();
  5. $categoryId = Category::find()->group('categoryGroup')->slug('category-slug')->ids();
  6. $excludeIds = Entry::find()->relatedTo($tagIds)->ids();
  7.  
  8. return [
  9. 'serializer' => 'jsonFeed',
  10. 'elementType' => craftelementsEntry::class,
  11. 'criteria' => [
  12. 'section' => 'blog',
  13. 'id' => 'not ' . implode($excludeIds),
  14. 'relatedTo' => [
  15. 'targetElement' => $categoryId,
  16. 'field' => 'categories'
  17. ],
  18. ],
  19. 'transformer' => function(craftelementsEntry $entry) {
  20. return [
  21. 'title' => $entry->title,
  22. 'url' => $entry->url,
  23. ];
  24. },
  25. 'pretty' => true,
  26. ];
  27. }
RAW Paste Data