orderby_values

Type: array
Possible values: An array of orderby values, each storing an array of up to three sub-parameters: 'label', 'meta_key', and 'orderby'

This is a special parameter that can be used with orderby fields in place of the values parameter.

This parameter accepts an array of orderby options, each storing an array of up to three parameters (label, meta_key, and orderby).

Sub-parameters

  • label – (string) Sets the label for this field option
  • meta_key – (boolean) Accepts either true or false. Set to true to indicate that this orderby value is a meta_key.
  • orderby – (string) Relevant only when ‘meta_key’ is set to ‘true’. Accepts either ‘meta_value’ or ‘meta_value_num’. Use ‘meta_value_num’ for meta values that are numeric. See the official WP_Query documentation for more details.

Example

The following code was used in a search form for an events directory. It establishes an orderby field which allows the user to order results by either title or event_date (a custom meta key). We use the ‘orderby_values’ parameter to customize our options for each case. Note that we only use the ‘meta_key’ and ‘orderby’ options for ‘event_date’, since that is a meta key. ‘title’ is a natively recognized orderby parameter so we only need to specify a label.

$args['fields'][] = array(
                     'type' => 'orderby',
                     'format' => 'radio',
                     'default' => 'event_date',
                     'title' => 'Order by',
                     'orderby_values' => 
                           array(
                               'event_date' => array('label' => 'Date', 
                                                     'meta_key' => true, 
                                                     'orderby' => 'meta_value'),
                               'title' => array('label' => 'Name'),
                            ));

Fields that use this parameter