Title: change code to random sort
Last modified: January 18, 2017

---

# change code to random sort

 *  [fistcloud](https://wordpress.org/support/users/fistcloud/)
 * (@fistcloud)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/change-code-to-random-sort-2/)
 * Hi
    plz I want to change the code
 *     ```
       <div class="properties-filter-sort-by-wrapper">
       				<select class="form-control" name="filter-sort-by">
       					<option value=""><?php echo __( 'Sort by', 'realia' ); ?></option>
       					<option value="price" <?php if ( ! empty( $_GET['filter-sort-by'] ) && 'price' == $_GET['filter-sort-by'] ) :   ?>selected="selected"<?php endif; ?>><?php echo __( 'Price', 'realia' ); ?></option>
       					<option value="title" <?php if ( ! empty( $_GET['filter-sort-by'] ) && 'title' == $_GET['filter-sort-by'] ) :   ?>selected="selected"<?php endif; ?>><?php echo __( 'Title', 'realia' ); ?></option>
       					<option value="published" <?php if ( ! empty( $_GET['filter-sort-by'] ) && 'published' == $_GET['filter-sort-by'] ) :   ?>selected="selected"<?php endif; ?>><?php echo __( 'Published', 'realia' ); ?></option>
       				</select>
       			</div><!-- /.filter-sort-by-wrapper -->
       ```
   
 * And replace by defalut to random and if possible to hide (Sorting options and
   Order)
 * tanks to all
    -  This topic was modified 9 years, 4 months ago by [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/).
    -  This topic was modified 9 years, 4 months ago by [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/).

Viewing 1 replies (of 1 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/change-code-to-random-sort-2/#post-8674833)
 * You can hide the sorting options with CSS
 *     ```
       .properties-filter-sort-by-wrapper {
          display: none;
       }
       ```
   
 * To achieve random order, assuming the listing is achieved with the WP_Query class,
   use the “[pre_get_posts](https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts)”
   action. What ever you do in this action will affect all post queries, so you 
   either should conditionally add your callback only when needed or place a conditional
   within the callback so the random ordering is only applied to queries where it
   is wanted.
 * Aside from the conditionals, set the ‘[orderby](https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters)‘
   query var to ‘rand’.

Viewing 1 replies (of 1 total)

The topic ‘change code to random sort’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [9 years, 4 months ago](https://wordpress.org/support/topic/change-code-to-random-sort-2/#post-8674833)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
