Title: sorting query_post
Last modified: August 21, 2016

---

# sorting query_post

 *  [radzo1](https://wordpress.org/support/users/radzo1/)
 * (@radzo1)
 * [13 years ago](https://wordpress.org/support/topic/sorting-query_post/)
 * Hey there,
    I just want to sort the posts by a custom field in the wp_post table
   named event_date (mysql->datetime) the filter_where returns the correct week 
   by a number. The orderby and order argument does’t work as well as an filter_orderby.
   Is there any other solution to sort the query_post or the returning object?!
 *     ```
       function filter_where($where = '') {
       		$week = date("W");
       		$week = $week + $_SESSION['count'];
       	        $where .= " AND event_week =".$week ;
       	    return $where;
       	  }
       add_filter('posts_where', 'filter_where');
   
       query_posts(array('post_type'=>'portfolio', 'paged'=>$paged,
       'portfolio-category'=>$port_cat, 'posts_per_page'=>$port_num_fetch));
       ```
   
 * I’ve tried it with
 *     ```
       query_posts(array('post_type'=>'portfolio', 'paged'=>$paged,
       'portfolio-category'=>$port_cat, 'posts_per_page'=>$port_num_fetch,
       'orderby =>'event_date', 'order'=>'DESC'));
       ```
   
 * and
 *     ```
       function filter_orderby($orderby = ''){
       	$orderby = 'event_week';
       	 return $orderby;
       	 }
       function filter_order($order = ''){
       	$order = 'ASC';
       	return $order;
       	}
   
       // ORDER BY
       add_filter('posts_orderby','filter_orderby');
       add_filter('posts_order','filter_order');
       ```
   

The topic ‘sorting query_post’ is closed to new replies.

## Tags

 * [query_post](https://wordpress.org/support/topic-tag/query_post/)
 * [sort](https://wordpress.org/support/topic-tag/sort/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [radzo1](https://wordpress.org/support/users/radzo1/)
 * Last activity: [13 years ago](https://wordpress.org/support/topic/sorting-query_post/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
