Term Custom Post Order
A custom Wordpress plugin to allow the ordering of posts differently within each taxonomy term.
by Brianna Deleasa · github.com/bdeleasa/term-custom-post-order · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/bdeleasa/term-custom-post-order/archive/refs/heads/main.zipOrder posts differently within each taxonomy term. Perfect for displaying the same posts in different orders on different pages.
Description
This WordPress plugin allows you to set custom ordering for posts within specific taxonomy terms. For example, if you have a "Testimonial" post type with a "Testimonial Category" taxonomy containing "Home" and "About" terms, you can display the testimonials in one order on the Home page but a different order on the About page.
Key Features
- Term-based ordering: Set different post orders for the same posts within different taxonomy terms
- Drag-and-drop interface: Intuitive admin interface for reordering posts
- Quick action links: Direct access to reorder posts from taxonomy term list pages
- Flexible configuration: Enable ordering for specific post type/taxonomy combinations
- Auto-modify queries: Optionally automatically apply custom ordering to queries
- Elementor integration: Built-in support for Elementor Loop Grid and Loop Carousel widgets
- Developer-friendly: Use
orderby => 'term_order'in your queries for explicit control, or use convenient template tag functions
Installation
- Upload the
term-custom-post-orderfolder to the/wp-content/plugins/directory - Activate the plugin through the 'Plugins' menu in WordPress
- Go to Settings > Term Post Order to configure which post types and taxonomies should support custom ordering
- Use Term Post Order menu to reorder posts within terms
Configuration
1. Enable Post Type/Taxonomy Combinations
Go to Settings > Term Post Order and add the post type/taxonomy combinations you want to enable:
- Select a post type (e.g., "Testimonials")
- Select a taxonomy (e.g., "Testimonial Category")
- Click "Add Combination" to add more
- Click "Save Changes"
2. Configure Auto-Modify Queries (Optional)
Enable the "Auto-modify Queries" option if you want the plugin to automatically apply custom term ordering to queries that:
- Filter by a term
- Order by
menu_order
When disabled (default), you must explicitly use orderby => 'term_order' in your queries.
Usage
Admin Interface
Method 1: From the Term Post Order Menu
- Go to Term Post Order in the WordPress admin menu
- Select a post type from the dropdown
- Select a taxonomy from the dropdown
- Select a specific term from the dropdown
- Drag and drop posts to reorder them
- Click "Save Order" to save your changes
Method 2: Quick Link from Taxonomy Pages
When viewing taxonomy term lists (e.g., Categories, Tags, or custom taxonomies), you'll see a "Post Order" quick action link for each term (if the combination is enabled in settings).
- Navigate to any taxonomy page (e.g., Posts > Categories or your custom taxonomy)
- Hover over a term to reveal row actions
- Click the "Post Order" link
- The Term Post Order page will open with that term pre-selected
- Drag and drop posts to reorder them
- Click "Save Order" to save your changes
This quick link provides instant access to reorder posts for a specific term without manually navigating through dropdowns.
Querying Posts with Custom Order
Method 1: Explicit orderby Parameter
$args = array(
'post_type' => 'testimonial',
'tax_query' => array(
array(
'taxonomy' => 'testimonial_category',
'field' => 'slug',
'terms' => 'home',
),
),
'orderby' => 'term_order',
'order' => 'ASC',
);
$query = new WP_Query( $args );
Method 2: Auto-Modify (if enabled in settings)
$args = array(
'post_type' => 'testimonial',
'tax_query' => array(
array(
'taxonomy' => 'testimonial_category',
'field' => 'slug',
'terms' => 'home',
),
),
'orderby' => 'menu_order', // Will be automatically converted to term order
'order' => 'ASC',
);
$query = new WP_Query( $args );
Block Editor / Gutenberg
When using the Query Loop block or similar blocks that filter by terms, you can:
- Enable "Auto-modify Queries" in settings, OR
- Use a custom query filter to set
orderbytoterm_order
Page Builders
Most page builders that support query filtering by terms will work with this plugin when "Auto-modify Queries" is enabled.
Elementor Integration
The plugin includes built-in support for Elementor's Loop Grid and Loop Carousel widgets via Query ID.
How to Use:
- Edit your Loop Grid, Loop Carousel, or Posts widget in Elementor
- Go to the Query section
- Scroll to the Advanced tab (or look for "Query ID")
- Set the Query ID field to:
tcpo_term_order - Make sure your query is filtered by a taxonomy term (under Include → Term)
- Update/Publish the page
Example Setup:
Query Settings:
├── Source: Posts (or your custom post type)
├── Include
│ └── Term: Select your term (e.g., "Home" from "Testimonial Category")
├── Advanced
│ └── Query ID: tcpo_term_order
└── Order By: Any (will be overridden)
That's it! Your posts will now display in the custom order you set for that specific term.
Alternative Query ID: You can also use term_order as the Query ID (both work the same).
Developer Information
Data Storage
The plugin stores custom post orders in term meta:
- Meta key:
_tcpo_post_order - Format: Serialized array mapping post IDs to order values
- Example:
array( 123 => 1, 456 => 2, 789 => 3 )
Filters and Actions
Filter: posts_clauses
The plugin hooks into posts_clauses to modify query clauses when term ordering is requested.
Filter: posts_orderby
Adds secondary ordering by post title for posts with the same order value.
Template Tags
The plugin provides convenient template tag functions for easier usage in themes and plugins.
Get Custom Order for a Term
$term_id = 123;
$order_data = tcpo_get_term_post_order( $term_id );
// Returns: array( 123 => 1, 456 => 2, 789 => 3 )
// Or empty array if no custom order exists
Update Custom Order for a Term
$term_id = 123;
$order_data = array(
123 => 1, // Post ID 123 has order 1
456 => 2, // Post ID 456 has order 2
789 => 3, // Post ID 789 has order 3
);
$success = tcpo_update_term_post_order( $term_id, $order_data );
// Returns: true on success, false on failure
Delete Custom Order for a Term
$term_id = 123;
$success = tcpo_delete_term_post_order( $term_id );
// Returns: true on success, false on failure
Get Order Value for a Specific Post in a Term
$post_id = 123;
$term_id = 456;
$order_value = tcpo_get_post_order_in_term( $post_id, $term_id );
// Returns: integer order value, or null if no custom order exists
Check if a Term Has Custom Ordering
$term_id = 123;
$has_order = tcpo_has_custom_order( $term_id );
// Returns: true if term has custom ordering, false otherwise
Programmatic Usage (Advanced)
Check if Combination is Enabled
use TermCustomPostOrder\Settings;
$is_enabled = Settings::is_combination_enabled( 'testimonial', 'testimonial_category' );
Get Plugin Settings
use TermCustomPostOrder\Settings;
$settings = Settings::get_settings();
$auto_modify = $settings['auto_modify_queries'];
$combinations = $settings['enabled_combinations'];
Direct Term Meta Access (Alternative)
You can also access the data directly using WordPress term meta functions:
// Get custom order
$term_id = 123;
$custom_order = get_term_meta( $term_id, '_tcpo_post_order', true );
// Update custom order
$order_data = array( 123 => 1, 456 => 2, 789 => 3 );
update_term_meta( $term_id, '_tcpo_post_order', $order_data );
// Delete custom order
delete_term_meta( $term_id, '_tcpo_post_order' );
Note: Using the template tag functions is recommended as they include validation and error handling.
Requirements
- WordPress: 6.0 or higher
- PHP: 8.2 or higher
Frequently Asked Questions
Q: What happens to posts that don't have a custom order set?
A: Posts without a custom order will default to order value 0 (same as the default menu_order value).
Q: Can I use this with custom post types?
A: Yes! The plugin works with any public post type, including custom post types.
Q: Does this work with hierarchical taxonomies?
A: Yes, the plugin works with both hierarchical (like categories) and non-hierarchical (like tags) taxonomies.
Q: Will this affect my existing queries?
A: Only if you enable "Auto-modify Queries" in settings. Otherwise, you must explicitly use orderby => 'term_order'.
Q: Can I order posts for multiple terms at once?
A: No, ordering is done per-term to allow for different orders in different contexts.
Q: What if a post belongs to multiple terms?
A: Each term maintains its own order, so the same post can have different orders in different terms.
Q: How do I use this with Elementor?
A: In any Elementor widget with a Query section (Loop Grid, Loop Carousel, Posts widget), simply set the Query ID field to tcpo_term_order in the Advanced tab. Make sure your query is filtered by a taxonomy term, and the custom ordering will be applied automatically.
Q: Does this work with Elementor Pro's Posts widget?
A: Yes! It works with all Elementor widgets that have query capabilities: Loop Grid, Loop Carousel, Posts widget, and more. Just set the Query ID to tcpo_term_order.
Q: How do I quickly access the ordering page for a specific term?
A: When viewing any taxonomy term list page (e.g., Categories, Tags, or custom taxonomies), hover over a term and you'll see a "Post Order" quick action link. Clicking this link takes you directly to the reordering page with that term already selected.
Changelog
1.0.2
- Small spelling error.
1.0.1
- Fixing an issue where the Elementor query ID's weren't working properly to reorder the posts.
1.0.0
- Initial release
- Drag-and-drop interface for reordering posts
- Settings page for enabling post type/taxonomy combinations
- Optional auto-modify queries feature
- Support for custom orderby parameter
- Built-in Elementor integration for Loop Grid and Loop Carousel widgets
- Post status indicators in admin interface
- Accurate post counts per post type in term selection
- Quick action links on taxonomy term list pages for instant access to reordering
- Template tag functions for easier developer usage:
tcpo_get_term_post_order()- Get custom order for a termtcpo_update_term_post_order()- Update custom order for a termtcpo_delete_term_post_order()- Delete custom order for a termtcpo_get_post_order_in_term()- Get order value for a specific post in a termtcpo_has_custom_order()- Check if term has custom ordering
Credits
Developed by Brianna Deleasa me@briannadeleasa.com
License
This plugin is licensed under the GPL v2 or later.
License URI: https://www.gnu.org/licenses/gpl-2.0.html