Loop – Remove filter by post_order and then add it back

To add a removed filter back you need to know what was originally installed in the first place. you can crawl global $wp_filter array, but it should do the same with very little effort:

function remove_query_order($order) {
  remove_filter('posts_orderby','remove_query_order',PHP_INT_MAX);
  return '';
}
add_filter('posts_orderby','remove_query_order',PHP_INT_MAX);

Add the filter before the query you want it to take effect and it will remove itself.

Leave a Comment