Documentation - How To - Ignore sort apply for custom query when using Autosort on Advanced Taxonomy Terms Order plugin

Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInPrint this page

Ignore sort apply for custom query when using Autosort on Advanced Taxonomy Terms Order plugin

When using the Advanced Taxonomy Terms Order plugin, custom sorting for taxonomy terms can be easily applied across your website by adding a simple argument to your query:

'orderby' => 'term_order'

This method is straightforward and works well in most cases. However, if your project involves a large number of taxonomy queries, updating the code manually for each instance might not be the most efficient approach. To address this, the plugin provides an Autosort option.

What is Autosort?

The Autosort setting in the Advanced Taxonomy Terms Order plugin allows you to enforce custom sorting automatically for all taxonomy queries across your site. When this option is enabled, you don’t need to modify individual queries; the plugin automatically applies the custom order you’ve set, ensuring consistency across all front-end displays.

Handling Specific Queries with Default Sorting

While Autosort is incredibly useful for applying custom orders globally, there may be scenarios where you need to retrieve taxonomy terms in their default order for specific queries. Fortunately, the plugin provides a simple way to bypass the Autosort functionality for individual cases.

To retrieve terms in their default order, add the following argument to your query:

'ignore_custom_sort' => TRUE

Example Usage

Here’s an example of how you might implement this in your code:

$terms = get_terms(array(
    'taxonomy' => 'category',
    'ignore_custom_sort' => TRUE,
));

In this example, the get_terms function retrieves the terms from the category taxonomy without applying the custom sort order, even if Autosort is enabled.

The Advanced Taxonomy Terms Order plugin’s Autosort feature is a powerful tool for managing custom sorting across your site. However, it’s equally important to know how to selectively bypass this feature when necessary. By using the ignore_custom_sort argument, you can fine-tune your queries, ensuring that the terms are displayed in their default order where needed.

This approach gives you the flexibility to use custom sorting globally while retaining control over specific queries, allowing you to create more nuanced and customized WordPress experiences.