This parameter is applicable to the read-only operations, i.e to use with the get operator.
Some methods support the parameter combined with the edit operator to re-sort objects.
Default sorting depends on the applied method.
orders is an array of fieldOrder sortable field objects.
A sortable field object has the following properties:
In the below example, we'll get a list of keywords added to the NN project and sorted alphabetically in the ascending order.
POST /v2/json/get/keywords_2/keywords/
{"project_id": /* project id (int) */}
{"result":[{"id":"80764821","name":"test keyword 1"},{"id":"80764822","name":"test keyword 2"},{"id":"80764823","name":"test keyword 3"},{"id":"80764824","name":"test keyword 4"},{"id":"80764825","name":"test keyword 5"}]}
POST /v2/json/get/keywords_2/keywords/
{"project_id": /* project id (int) */, "orders":[{"name":"name","direction":"DESC"}]}
{"result":[{"id":"80764825","name":"test keyword 5"},{"id":"80764824","name":"test keyword 4"},{"id":"80764823","name":"test keyword 3"},{"id":"80764822","name":"test keyword 2"},{"id":"80764821","name":"test keyword 1"}]}
In the below example, we'll get a list of keywords added to the NN projects and sorted alphabetically in the ascending order.
<?php $projectId = '%NN%'; // ID of your project $TVSession = new TVSession(); $selectorKeywords = new TVPen($TVSession, 'get', 'keywords_2', 'keywords'); $selectorKeywords->setData(['project_id' => $project_id]); $selectorKeywords->serOrders([ TVFields::genOrderData('name', 'DESC') ]); $page = $selectorKeywords->exec(); if(is_null($page->getResult())) return var_dump($page->getErrors()); // $page - array of keywords foreach($page->getResult() as $resultItem){ var_dump($resultItem); }