I want to get posts in the order that I request.
Luckly, there was a query argument -> orderby = 'post_name__in'.
But, I get posts in other order.
And I see the query's request.
Here
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID
FROM wp_posts
WHERE 1=1
AND wp_posts.post_name
IN (
'post title 1',
'post title 2',
'post title 3',
)
AND wp_posts.post_type = 'post'
AND ((wp_posts.post_status = 'publish'))
ORDER BY wp_posts.menu_order,
FIELD(
wp_posts.post_name,
'post title 1',
'post title 2',
'post title 3',
)
LIMIT 0, 9
I find that ORDER BY wp_posts.menu_order was a problem.
If I delete it and then Query on phpmyadmin, It works well.
I get posts in the order that I want.
So, how can I delete that ORDER BY wp_posts.menu_order by using hook & filter or some other wordpressful way ?
I found answer!
the wp_posts.menu_order was added because of Post Types Order plugin.
In this plugin,
add_filter('posts_orderby', array($this, 'posts_orderby'), 99, 2);
~
~
~
//check for ignore_custom_sort
if (isset($query->query_vars['ignore_custom_sort']) && $query>query_vars['ignore_custom_sort'] === TRUE)
return $orderBy;
if(trim($orderBy) == '')
$orderBy = "{$wpdb->posts}.menu_order " . $order;
else
$orderBy = "{$wpdb->posts}.menu_order". $order .", " . $orderBy;
~
~
return $orderBy;
So, I add $args['ignore_custom_sort'] = true to my query argument.
And this works!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With