Title: Add filter to Orderby Parameter using Array
Last modified: August 22, 2016

---

# Add filter to Orderby Parameter using Array

 *  [nfluense](https://wordpress.org/support/users/nfluense/)
 * (@nfluense)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/add-filter-to-orderby-parameter-using-array/)
 * Using WP-Query, I’m setting the Orderby parameter using an array:
 *     ```
       $events_args = array(
       	'post_status' => 'publish',
       	'post_type' => 'events',
       	'meta_key' => 'start_time',
       	'meta_type' => 'DATETIME',
       	'orderby' => array( 'meta_value_num' => 'DESC', 'title' => 'ASC' ),
       	'order' => 'ASC',
       	'posts_per_page'	=> -1,
       	'meta_query' => array(
       	        array(
       		        'key'		=> 'event_date',
       		        'compare'	=> '=',
       		        'value'		=> 20150225,
       		    )
       	    )
       );
       ```
   
 * I need to filter the first item in the array (meta_value_num). Using `add_filter`,
   how can I access the first item of the Orderby array to make the adjustments 
   I need?
 * Thank you!

Viewing 1 replies (of 1 total)

 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [11 years, 4 months ago](https://wordpress.org/support/topic/add-filter-to-orderby-parameter-using-array/#post-5680299)
 * You can’t. You control the query parameters, so there’s no filter for them. It’s
   presumed you can change them yourself directly before making the query. The only
   things you can filter from the WP_Query are basically the final results after
   it’s been turned into segments of the SQL statement.
 * If you need to filter in many ways without modifying the query directly, modify
   the query to have its own custom filter which you can hook into elsewhere:
 * `'orderby' => array( 'meta_value_num' => apply_filters('custom_filter_name', '
   DESC'), 'title' => 'ASC' ),`

Viewing 1 replies (of 1 total)

The topic ‘Add filter to Orderby Parameter using Array’ is closed to new replies.

## Tags

 * [add_filter](https://wordpress.org/support/topic-tag/add_filter/)
 * [array](https://wordpress.org/support/topic-tag/array/)
 * [orderby](https://wordpress.org/support/topic-tag/orderby/)
 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * Last activity: [11 years, 4 months ago](https://wordpress.org/support/topic/add-filter-to-orderby-parameter-using-array/#post-5680299)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
