Sorting

How to configure query sorting.

Features, widgets and plugins that use Open Content queries within Naviga Web use the built in sorting.

Everyware 1.x+ is required for Open Content 3.0

Predefined sortings stored in Open Content were removed with OC 3.0. Applications using Open Content 3.0 must specify the sorting on API call instead.

Configuration

1. Add your own sorting configuration in your project.

  • name - Shown in widgets and plugins.

  • contentType - Valid for just one content type. Set null for any.

  • sortIndexFields - Array or sortings, all with indexField and ascending.

  • defaultSorting - Name of the sorting that should be used as default in case none is selected in the widget/plugin.

Example config

exampleChildThemeSortConfig.json
{
  "sortings": [{
    "name": "Teaser headline",
    "contentType": null,
    "sortIndexFields": [{
      "indexField": "TeaserHeadline",
      "ascending": "false"
    },
    {
      "indexField": "Pubdate",
      "ascending": "false"
    }]
  },
  {
    "name": "Name",
    "contentType": null,
    "sortIndexFields": [{
      "indexField": "Name",
      "ascending": "false"
    },
    {
      "indexField": "Pubdate",
      "ascending": "false"
    }]
  },
  {
    "name": "Pubdate latest first",
    "contentType": null,
    "sortIndexFields": [{
      "indexField": "Pubdate",
      "ascending": "false"
    }]
  },
  {
    "name": "Pubdate oldest first",
    "contentType": null,
    "sortIndexFields": [{
      "indexField": "Pubdate",
      "ascending": "true"
    }]
  }],
  "defaultSorting": "PubDate"
}

2. Use your sort configuration

add_filter('ew_oc_sort_config_path', static function (){
    return get_stylesheet_directory() . '/childThemeSortConfig.json';
});

Default

If you don't specify anything, this will be used.

default_sort_options_config.json
{
  "sortings": [{
    "name": "PubDate",
    "contentType": null,
    "sortIndexFields": [{
      "indexField": "Pubdate",
      "ascending": "false"
    }]
  }],
  "defaultSorting": "PubDate"
}

****

Priority

When fetching sorting config the plugin will follow a certain priority:

  1. If there is any config provided with the ew_oc_sort_config_path filter then the plugin will use that.

  2. Sorting config fetched from OC.

  3. The default sorting config provided by the plugin.

Last updated