Monday, November 25, 2013

Solution to order pages/posts specific by id in array with WP Query

Have you had problem with not getting the specific posts displaying in the order you have wanted it to be. Normally the Wordpress WP Query is sorted by the post title but what if you don't want to order the query and just have it "un-ordered", the way you write the id's to be.

The solution to this problem is to order your result with the pages to get.

$you_query = new WP_Query(array('post_type' => 'page', 'post__in' => 'array(12, 10, 18, 22)', 'orderby' => 'post__in'));

So that's how you order your result with your array or string of posts. No manual need of ordering or any other hassling.

No comments:

Post a Comment