WPThumbs
Themes Plugins By purpose By industry Best-of lists Fix it guides
Free Plugin by Tubal v1.1

Sort Query Posts

Sort posts on-the-fly without making a new SQL query

Sort Query Posts

The facts

Rating
5★ from 3
Active installs
100+
Price
Free
Last updated
4 Sep 2012
Added
Jan 2011
Requires WP
2.5
Tested up to
WP 3.4.2
Downloads
12,177

Our analysis

AI-assisted

Sort Query Posts is a WordPress plugin designed to sort posts dynamically without executing a new database query, which can enhance performance. It allows you to reorder various types of posts, including custom post types, using a simple function call before displaying the posts.

The plugin supports multiple sorting criteria such as author, date, title, and more. It is particularly useful for developers who need to adjust the order of posts returned by WordPress queries without impacting site performance.

Best for: This plugin is suitable for developers looking to efficiently sort posts on their WordPress sites.

What it does well

  • Lightweight with only 73 lines of code
  • No additional database queries required for sorting
  • Supports sorting of custom post types
  • Allows sorting by multiple criteria

Where it falls short

  • Limited to certain order values; does not support meta_value or meta_value_num
  • Last updated in September 2012, may not be compatible with newer WordPress versions

Verdict

Sort Query Posts offers a straightforward solution for sorting posts without performance drawbacks, but its age and limited sorting options may be a concern for some users.

From the developer

Tubal's own description of Sort Query Posts, lightly tidied.

A really simple and lightweight plugin (73 lines of code – comments included) to sort posts on-the-fly without making a new query to the database (improves performance).

Features:

  • Supports all order_by and order values of the query_posts function except meta_value and meta_value_num (which require a database query).
  • Supports changing the order of all types of posts, including custom post type posts and custom post type “archive” posts.

Documentation

This plugin adds the function sort_query_posts_by(string $order_by [, string $order]) to the global context.
The second $order parameter is optional. Its default value is asc (ascending order).

Call this function before the loop to change how posts are ordered.
After calling this function you can show the posts as you normally would.

You can sort posts by:

  • author
  • comment_count
  • date
  • id
  • menu_order
  • modified
  • parent
  • title

This is specially useful in two cases:

  • When you need to reorder the posts returned by the query that WordPress creates from your given URL. Custom post type “archive” posts are a great example of this case.
  • When you need the posts returned by your customized query (e.g. query_posts()) to be shown more than once on the same page and ordered differently.

Examples:

<?php sort_query_posts_by('title', 'desc'); ?>

The example above will sort posts by their title in descending order without making a new query to the database.
This way sorting is performance friendly.

<?php sort_query_posts_by('ID'); ?>

The example above will sort posts by their ID in ascending order.

<?php sort_query_posts_by('rand'); ?>

Read the full description on the official page →

Tagged as

Alternatives

Other plugins for custom content structures.

Ad Inserter

Manage Google AdSense ads, banners, ad rotation, sticky widgets, AMP ads, ads.txt, tracking, header and footer...

Free 300k+ installs 4.9★ (2,428)
Advanced Custom Fields

ACF helps customize WordPress with powerful, professional and intuitive fields. Proudly powering over 2 millio...

Free 2M+ installs 4.5★ (1,438)
Simple Custom Post Order

Easily reorder posts, pages, custom post types, and taxonomies with intuitive drag-and-drop sorting in the Wor...

Free 300k+ installs 4.8★ (569)
WP Activity Log

The #1 user-rated activity log plugin for event logging, activity monitoring and change tracking.

Free 300k+ installs 4.7★ (488)
Custom Post Type UI

Admin UI for creating custom content types like post types and taxonomies

Free 1M+ installs 4.6★ (276)