Ignore sort apply for certain query on Post Types Order
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
Example
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; }
For Advanced Post Types Order plugin use “apto/ignore_custom_order” filter.
Example
The following code ignore the sort apply for any query which include ‘reports’ post type
add_filter('apto/ignore_custom_order', 'apto_ignore_custom_order', 10, 3); function apto_ignore_custom_order($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; }
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;
}
Thanks for reporting this.