So I have a review plugin that is automatically sorting all my site based on the score rating. It seems here are the filters the plugin is applying globally:

    //Post sorting
    $sort = get_option('rs_sort');
    if ($sort == 'rating') {

        add_filter('posts_fields', 'rs_weighted_fields');
        add_filter('posts_join', 'rs_weighted_join');
        add_filter('posts_groupby', 'rs_weighted_groupby');
        add_filter('posts_orderby', 'rs_weighted_orderby');

    } else if ($sort == 'comments') {
        add_filter('posts_orderby', 'rs_comments_orderby');


These filters are taking priority over the whole site. Even some custom loops where I want it to use the wordpress default (sort by newest) and others where I want to sort by random.

Specifically here is an example loop that I am trying to make:

<?php $custom_query = new WP_Query('category_name=FreaturedIndex&orderby=rand'); ?><?php while ($custom_query->have_posts()) : $custom_query->the_post(); ?>

Right now, its just sorting by rating and ignoring the orderby=rand. Is there some code that can be applied to remove these filters by applying it to specific queries?

Thanks for the help!

1 Answer 1


How about doing remove_filter( 'posts_orderby', 'rs_weighted_orderby' );? If that doesn't work, you could apply your own filters with higher priorities...but that's sorta hackey, and I would avoid it if possible.

  • If I add that code into the blog, will it remove it completely from the site? I still want this sort system running on all of the main loops but not some specific pages like "newly submitted hosts" or the featured box that I want it to be sorted randomly. Just confirming. Feb 1, 2012 at 2:33
  • I can't say for certain if it would even remove it. That's just the method to remove a filter. You can remove it conditionally, with something like if_page(), but you'll have to develop your own logic for that and what not, it's a completely separate issue (ie: if you have a question about it, handle it in a new question not in comments). I suggest you just try it. Worst case you change the sort order for your site for a little. You're not writing anything to the DB, so none of this would effect permanent change.
    – mor7ifer
    Feb 1, 2012 at 2:37
  • So to test it on a page where I dont want the rating sort to be there, I would whip something like this: 'code'if_page(coupons) {remove_filter( 'posts_orderby', 'rs_weighted_orderby' );}'/code' Where would I put it, the header? Feb 1, 2012 at 2:39
  • You would add it to functions.php (or anywhere else really, put it where it makes sense to you), and it's is_page(), I misspoke (always check facts, especially with a resource like the codex at your fingertips). I suggest you read up on Conditional Tags if you want to design any sort of serious logic for which pages do and don't use their sort feature.
    – mor7ifer
    Feb 1, 2012 at 2:46
  • Remove filter wouldn't have done that, check your work. I strongly recommend you read through the functions that the filters are calling. See what each of them does, see if there is a better filter to modify or remove...my answer was not intended as specifically as you seem to have taken it.
    – mor7ifer
    Feb 1, 2012 at 3:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.