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