• 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.