Title: posts_orderby exclude section from sorting
Last modified: November 6, 2022

---

# posts_orderby exclude section from sorting

 *  [temporalnaut](https://wordpress.org/support/users/temporalnaut/)
 * (@temporalnaut)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/posts_orderby-exclude-section-from-sorting/)
 * Hi, I use this code to sort the products randomly:
 *     ```
       session_start();
   
       add_filter( 'posts_orderby', 'misha_rand_order_with_seed' );
   
       function misha_rand_order_with_seed( $orderby_statement ){
   
           if( !is_shop() && !is_product_category() ) return $orderby_statement;
   
           $seed = $_SESSION['seed'];
           if (empty($seed)) {
             $seed = rand();
             $_SESSION['seed'] = $seed;
           }
   
           $orderby_statement = 'RAND('.$seed.')';
           return $orderby_statement;
       }
       ```
   
 * how can I make sure that the row of products located right above the footer is
   not affected by it? I mean the 6 squares at the bottom of the page, it’s a Portfolio
   widget from the Elementor plugin. Thank you.
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fposts_orderby-exclude-section-from-sorting%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Moderator [threadi](https://wordpress.org/support/users/threadi/)
 * (@threadi)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/posts_orderby-exclude-section-from-sorting/#post-16169944)
 * Since [Elementor’s Portfolio widget is part of the Pro plugin](https://elementor.com/help/portfolio-widget-pro/),
   I would recommend you to contact Elementor support: [https://elementor.com/support/](https://elementor.com/support/)
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/posts_orderby-exclude-section-from-sorting/#post-16170859)
 * You could dump out the query’s `$query_vars` property and see if there is any
   value that you could use in a conditional to distinguish one query from the other.
   The query object is passed to the filter as a second parameter.
 * It’s also possible to have your callback remove itself from the filter call stack
   so it cannot influence subsequent queries.
    [https://developer.wordpress.org/reference/functions/remove_filter/](https://developer.wordpress.org/reference/functions/remove_filter/)

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘posts_orderby exclude section from sorting’ is closed to new replies.

## Tags

 * [products](https://wordpress.org/support/topic-tag/products/)
 * [sorting](https://wordpress.org/support/topic-tag/sorting/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 2 replies
 * 3 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [3 years, 7 months ago](https://wordpress.org/support/topic/posts_orderby-exclude-section-from-sorting/#post-16170859)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
