Change language settings to use Topvisor in your preferred language. You can select and set a preferred language later in the Account settings. Change language settings to use Topvisor in your preferred language. ru Русский Apply

Results sorting (orders)

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 parameter structure

orders is an array of fieldOrder sortable field objects.
A sortable field object has the following properties:

  • fieldOrder.name - field name
  • fieldOrder.direction - sorting order (ASC or DESC)

Examples

In the below example, we'll get a list of keywords added to the NN project and sorted alphabetically in the ascending order.

Request


POST /v2/json/get/keywords_2/keywords/

{"project_id": /* project id (int) */}

Result


 {"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"}]}
 

Request


POST /v2/json/get/keywords_2/keywords/

{"project_id": /* project id (int) */, "orders":[{"name":"name","direction":"DESC"}]}

Result


 {"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"}]}
 

SDK example

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 TV\Session();

 $selectorKeywords = new TV\Pen($TVSession, 'get', 'keywords_2', 'keywords');
 $selectorKeywords->setData(['project_id' => $project_id]);
 $selectorKeywords->serOrders([
 TV\Fields::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);
 }