3

Hopefully my titles makes some sense but I will try to elaborate.

I have a Channel entry called Movies that I am using the Element API to turn into JSON. There is a field inside that called Movie Genre which is an Entry type field.

When I create this transformer:

'transformer' => function(EntryModel $movie) {

                return [
                    'name' => $movie->title,
                    'genres' => $movie->movieGenre[0]->title
                ];
            },

This is the JSON I get now, which looks to me like it is gathering all entries, not just the ones inside the channel.

{"data":[{"name":"Harry Potter and The Order of the Phoenix","genres":"Fantasy"},{"name":"Jurassic World","genres":"Science Fiction"},{"name":"Romance","genres":null},{"name":"Science Fiction","genres":null},{"name":"Comedy","genres":null}, {"name":"Fantasy","genres":null},{"name":"Guardians of the Galaxy","genres":"Action"},{"name":"Horror","genres":null}, {"name":"Action","genres":null},{"name":"Home","genres":null}, {"name":"Thirteen Ghosts","genres":"Horror"}, {"name":"Movies","genres":null},{"name":"Genres","genres":null}],"meta": {"pagination": {"total":13,"count":13,"per_page":100,"current_page":1,"total_pages":1,"links":[]}}}

What I need to happen is only the Movies get returned as an item in the JSON and the movieGenre entry type not as its own item.

This is the desired JSON outcome.

{"data":[{"name":"Harry Potter and The Order of the Phoenix","genres":"Fantasy"},{"name":"Jurassic World","genres":"Science Fiction"},{"name":"Guardians of the Galaxy","genres":"Action"},{"name":"Thirteen Ghosts","genres":"Horror"}],"meta":{"pagination":{"total":13,"count":13,"per_page":100,"current_page":1,"total_pages":1,"links":[]}}}

  • I'm not sure I'm follow... can you edit the original question to show what your desired JSON output would be? – Brad Bell Nov 29 '15 at 16:46
  • Updated. Hopefully I have used my words better now. Thanks. – divinemonkey Nov 30 '15 at 6:57
1

I figured it out. Turned out I had entered the criteria incorrectly, as channel instead of section.

'criteria' => ['section' => 'movies'],

not

'criteria' => ['channel' => 'movies'],
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.