Sort Query by post_in Parameter WordPress

Allows post queries to sort the results by the order specified in the post__in parameter. Just set the orderby parameter to post__in! add_filter( ‘posts_orderby’, ‘sort_query_by_post_in’, 10, 2 ); function sort_query_by_post_in( $sortby, $thequery ) { if ( !empty($thequery->query[‘post__in’]) && isset($thequery->query[‘orderby’]) && $thequery->query[‘orderby’] == ‘post__in’ ) $sortby = “find_in_set(ID, ‘” . implode( ‘,’, $thequery->query[‘post__in’] ) . “‘)”;… Continue reading Sort Query by post_in Parameter WordPress

When should you use WP_Query vs query_posts() vs get_posts()?

query_posts() might be used in one and only case if you need to modify main query of page (for which there are better and more reliable methods to accomplish, over simplistic approach of this function). It sets a lot of global variables and will lead to obscure and horrible bugs if used in any other place… Continue reading When should you use WP_Query vs query_posts() vs get_posts()?