Last Updated:
Back to Main Index

get_sort_options() is one of 5 default helper functions defined in the Layers_Form_Elements class used specifically for defining the title and excerpt or header section of a form or widget.

Location: /core/helpers/forms.php


  • $options  – Existing option array if exists (optional)


When creating a new WP_Query(); , sorting requires two parameters, order and orderby. This would require two seperate inputs, which we like to avoid for UX reasons. The get_sort_options()  function allows us to use a single drop down to define two parameters at once.

Here’s a basic example of the usage.

The above will output the following HTML:

Since the option saves as JSON, on the front end you’ll need to decode the options. We will create a helper function for this at a later date.