Title: Using WP loop breaks filtering
Last modified: September 5, 2023

---

# Using WP loop breaks filtering

 *  [Dan204](https://wordpress.org/support/users/dan204/)
 * (@dan204)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/using-wp-loop-breaks-filtering/)
 * Hi there,
 * I’m trying to change the default post order on an archive page but having no 
   luck. I notice a similar question has already been asked [here](https://wordpress.org/support/topic/default-sorting-order/),
   and the response was to use [WP_Query](https://developer.wordpress.org/reference/classes/wp_query).
   Just to be clear, I’m not trying to sort posts using the FE sort widget, I’m 
   trying to simply change the default order posts appear when the page is loaded.
 * When using the standard loop on an archive page (as described in the WP_Query
   documentation), I notice the filters no longer work which leads me to believe
   the basic loop overrides the arguments that get added when a user clicks on a
   filter?
 * What is the correct way to ensure a custom loop changes the order of posts, but
   also respect the filter everything arguments?

Viewing 1 replies (of 1 total)

 *  Thread Starter [Dan204](https://wordpress.org/support/users/dan204/)
 * (@dan204)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/using-wp-loop-breaks-filtering/#post-17026770)
 * Just to follow up on this, I’ve stumbled across a way to order posts outside 
   of the loop which so far appears to have worked, for anyone else who’s interested
   the code I’ve added to my functions file is:
 *     ```wp-block-code
       add_filter("posts_orderby", "vmf_orderby_filter", 10, 2);
   
       function vmf_orderby_filter($orderby, &$query){
           global $wpdb;
           //figure out whether you want to change the order
           if (get_query_var("post_type") == "courses") {
                return "$wpdb->posts.post_title ASC"; //change post_title and ASC to suit using WP query parameters
           }
           return $orderby;
        }
       ```
   
 * The original code and explanation can be found [here](https://studiopress.community/topic/how-can-i-manually-change-posts-order-in-my-homepage/#post-204719).
 * I would still be interested to know what your recommendation would be to achieve
   this sort of ordering using the standard loop, but for now this appears to have
   gotten me out of trouble.

Viewing 1 replies (of 1 total)

The topic ‘Using WP loop breaks filtering’ is closed to new replies.

 * ![](https://ps.w.org/filter-everything/assets/icon-256x256.png?rev=3487105)
 * [Filter Everything — WordPress & WooCommerce Filters](https://wordpress.org/plugins/filter-everything/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/filter-everything/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/filter-everything/)
 * [Active Topics](https://wordpress.org/support/plugin/filter-everything/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/filter-everything/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/filter-everything/reviews/)

 * 1 reply
 * 1 participant
 * Last reply from: [Dan204](https://wordpress.org/support/users/dan204/)
 * Last activity: [2 years, 8 months ago](https://wordpress.org/support/topic/using-wp-loop-breaks-filtering/#post-17026770)
 * Status: not a support question