2

I'm looking for a way to order the ElementAPI json array by category and title. I can only get one to work whether it's 'group' => 'stockistRegion.first().title' or 'order' => 'title' using the criteria attribute.

Has anyone achieved this or know of a solution?

return [
    'endpoints' => [
        'stockists.json' => [
            'elementType' => 'Entry',
            'criteria' => [
                'section' => 'stockistsListing', 
                'search' => 'stockistRegion:*',
                'group' => 'stockistRegion.first().title', 
                'order' => 'title'
            ],
            'transformer' => function(EntryModel $entry) {
                return [
                    'title' => $entry->title,
                    'stockistWebsiteUrl' => (string)$entry->stockistWebsiteUrl[url],
                    'address' => $entry->stockistAddress1 . ', ' . $entry->stockistAddress2 . ' ' . $entry->stockistAddress3 . ' ' . $entry->stockistPostcode,
                    'formatted_address' => $entry->stockistAddress1 . '<br>' . $entry->stockistAddress2 . '<br>' . $entry->stockistAddress3 . '' . $entry->stockistPostcode,
                    'stockistAddress2' => $entry->stockistAddress2,
                    'stockistAddress3' => $entry->stockistAddress3,
                    'stockistPostcode' => $entry->stockistPostcode,
                    'stockistRegion' => (string)$entry->stockistRegion[0],
                    'latitude' => $entry->latitude,
                    'longitude' => $entry->longitude,
                    //'jsonUrl' => UrlHelper::getUrl("stockist/{$entry->id}.json"),
                ];
            },
        ],

    ]
];
  • 1
    It would be great if we can find a way for this to work. The alternative solution is to create my own JSON file without using ElementAPI, it's not as straightforward and tidy though. – Jack Stenson Nov 22 '16 at 16:20

Your Answer

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

Browse other questions tagged or ask your own question.