Ignore sort apply for certain query on Post Types Order

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

This replaced the deprecated filter pto/posts_orderby

The free WordPress plugin Post Types Order is already a “must have” code on any website. Control any post sorting through a nice and easy to use interface.

When Autosort is ON, the sorting is applied to all queries that match the post type. It can be forced by either using the ignore_custom_sort argument within the query , or by using a filter pto/posts_orderby/ignore which can be placed within any code, preferable on theme functions.php

The following code ignore the sort apply for any query which include ‘reports’ post type

	add_filter('pto/posts_orderby/ignore', 'theme_pto_posts_orderby', 10, 3);
    function theme_pto_posts_orderby($ignore, $orderBy, $query)
           if( (! is_array($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'reports') || 
                   (is_array($query->query_vars)   &&  in_array('reports', $query->query_vars)))
                   $ignore = TRUE;
           return $ignore;

Notify of
Newest Most Voted
Inline Feedbacks
View all comments

Thanks for the code. Got an unexpected ‘,’ error using this statement. Parentheses are misplaced. It should be

function theme_pto_posts_orderby($orderBy, $query) {
if ( ( !is_array( $query->query_vars['post_type'] ) && $query->query_vars['post_type'] == 'reports' ) ||
( is_array( $query->query_vars ) && in_array( 'reports', $query->query_vars ) ) ) {
return FALSE;

return $orderBy;