WordPress wp_query orderby not working

I am trying to get ordering working in wp_query, but posts are still being ordered with default settings (just tag__in is working). SQL query for posts looks like this:

string(379) "SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (81) ) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 3" 

Here is code snippet:

Read More
remove_all_filters('posts_orderby');
$tag = get_term_by('name', 'title_post', 'post_tag');
$args=array(
            'order'=>'ID',
            'orderby'=>'ASC',
            'tag__in' => $tag,
            'posts_per_page'=>3, // Number of related posts to display.
            'caller_get_posts'=>1
);

$my_query = new wp_query( $args );
var_dump($my_query->request);

Thanks!

Related posts

2 comments

  1. I have checked your code you have to pass wrong arguments.

    Can you please check below code?

    Wrong

    'order'=>'ID',
    'orderby'=>'ASC',
    

    Right

    'order'=>'ASC',
    'orderby'=>'ID',
    
  2. Ok, I switched order and orderby …
    So, correct arguments are ‘orderby’=>’ID’,’order’=>’ASC’,

Comments are closed.