This plugin hasn’t been tested with the latest 3 major releases of WordPress. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.

Sort Query by Post In


NOTE: This plug-in has been incorporated into WordPress core as of version 3.5.

Sort Query by Post In is a very light weight (less than 10 lines of code) plug-in intended for developers executing custom post queries. You’re welcome to include it in your theme and redistribute – just offer us some credit, please!

When constructing a WordPress post query in your theme template files or plug-in, WordPress offers the option to explicitly specify the posts to retrieve using the post__in parameter. Unfortunately, the orderby parameter does not offer an option that will sort the result by the exact order passed in the post__in parameter. This plug-in adds a post__in option for the orderby parameter that will order the result by the exact order specified in the post__in parameter.

And don’t worry about the plug-in being deactivated – your post queries with the new post__in value used for orderby will simply gracefully fall back to the default date sorting.


  1. Install easily with the WordPress plugin control panel or manually download the plugin and upload the extracted
    folder to the /wp-content/plugins/ directory
  2. Activate the plugin through the ‘Plugins’ menu in WordPress
  3. Modify the appropriate post queries with the orderby parameter set to post__in


query_posts( array( 'post__in' => array(20,10,106),  'orderby' => 'post__in' ) );

That will retrieve posts with IDs 20, 10, and 106 in that order!

Contributors & Developers

“Sort Query by Post In” is open source software. The following people have contributed to this plugin.




  • Automatically deactivates under WordPress 3.5 or newer (as it was folded into core)


  • Teeny code simplication, update support information


  • Dropped support for WordPress pre-3.0 (even lighter!)


  • Slightly more careful conditional check for sorting by post__in