Title: Random order blog posts
Last modified: January 27, 2021

---

# Random order blog posts

 *  [nicolasanderes](https://wordpress.org/support/users/nicolasanderes/)
 * (@nicolasanderes)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/random-order-blog-posts/)
 * Hello!
 * I have already read a lot on the subject, but somehow nothing really worked.
 * I would like to display the blogs on my site in a random order. The order should
   change as soon as the website is reloaded. Would you guys have any ideas about
   this? That would be great!
 * I would like to give you more info but don’t know what else you need….
 * Greetings and thanks in advance
    Nicolas
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Frandom-order-blog-posts%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 15 replies - 1 through 15 (of 17 total)

1 [2](https://wordpress.org/support/topic/random-order-blog-posts/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/random-order-blog-posts/page/2/?output_format=md)

 *  [Gustav](https://wordpress.org/support/users/4ever16/)
 * (@4ever16)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/random-order-blog-posts/#post-13963776)
 * Try searching random post plugin.
 * Maybe try this?
    [https://www.wpbeginner.com/wp-tutorials/how-to-display-random-posts-in-wordpress/](https://www.wpbeginner.com/wp-tutorials/how-to-display-random-posts-in-wordpress/)
 * Or this?
    [https://stackoverflow.com/questions/8672401/get-random-post-in-wordpress](https://stackoverflow.com/questions/8672401/get-random-post-in-wordpress)
    -  This reply was modified 5 years, 3 months ago by [Gustav](https://wordpress.org/support/users/4ever16/).
 *  Thread Starter [nicolasanderes](https://wordpress.org/support/users/nicolasanderes/)
 * (@nicolasanderes)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/random-order-blog-posts/#post-13964370)
 * Hey [@4ever16](https://wordpress.org/support/users/4ever16/)
 * Thanks for your reply, unfortunately neither worked as it either changed the 
   template or only worked for a “border section”…. :/
 *  [Gustav](https://wordpress.org/support/users/4ever16/)
 * (@4ever16)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/random-order-blog-posts/#post-13964385)
 * [@nicolasanderes](https://wordpress.org/support/users/nicolasanderes/) are those
   posts or pages and what theme do u use?
 *  Thread Starter [nicolasanderes](https://wordpress.org/support/users/nicolasanderes/)
 * (@nicolasanderes)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/random-order-blog-posts/#post-13964405)
 * [@4ever16](https://wordpress.org/support/users/4ever16/) We use the Peggi child
   theme.
 * These are individual posts that we display on one page/category for overview.(
   See the link above)
 *  [Gustav](https://wordpress.org/support/users/4ever16/)
 * (@4ever16)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/random-order-blog-posts/#post-13964520)
 * This code worked for me. Place it in functions.php
 *     ```
       add_action('pre_get_posts','alter_query');
       function alter_query($query){
           if ($query->is_main_query() &&  is_home())
               $query->set('orderby', 'rand'); //Set the order to random
       }
       ```
   
 *  Thread Starter [nicolasanderes](https://wordpress.org/support/users/nicolasanderes/)
 * (@nicolasanderes)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/random-order-blog-posts/#post-13964628)
 * Hey [@4ever16](https://wordpress.org/support/users/4ever16/)
 * Thanks a lot for your super help!
    Unfortunately I’m on the tube right now, I
   have inserted the code in functions.php, but it has not changed anything. I assume
   I have inserted it in the wrong place?
 * Where exactly should I place it?
 * Thank you very much!
 *  [Gustav](https://wordpress.org/support/users/4ever16/)
 * (@4ever16)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/random-order-blog-posts/#post-13964669)
 * 1. Are those posts or pages?
 * 2. Try to search for all functions.php and place code there.
 * 3. Go to settings click reading check latest post instead of a static page.
    -  This reply was modified 5 years, 3 months ago by [Gustav](https://wordpress.org/support/users/4ever16/).
 *  [Gustav](https://wordpress.org/support/users/4ever16/)
 * (@4ever16)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/random-order-blog-posts/#post-13964689)
 * Aha ok i know what the problem is wait i will answer soon.
    -  This reply was modified 5 years, 3 months ago by [Gustav](https://wordpress.org/support/users/4ever16/).
 *  Thread Starter [nicolasanderes](https://wordpress.org/support/users/nicolasanderes/)
 * (@nicolasanderes)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/random-order-blog-posts/#post-13964701)
 * [@4ever16](https://wordpress.org/support/users/4ever16/) you’re a hero! 🙂
 *  [Gustav](https://wordpress.org/support/users/4ever16/)
 * (@4ever16)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/random-order-blog-posts/#post-13964723)
 * First code worked but the problem is that the link you want to change is:
    [https://makerstars.org/category/mit-strom/](https://makerstars.org/category/mit-strom/)
   Instead of [https://makerstars.org/](https://makerstars.org/)
 * Try this.
 *     ```
       function wpse83754_filter_pre_get_posts( $query ) {
           if ( $query->is_main_query() && is_page( $id ) ) {
               $query->set( 'post_type', array( 'mit-strom' ) );
           }
       }
       add_action( 'pre_get_posts', 'wpse83754_filter_pre_get_posts' );
       ```
   
 * Or try this.
 *     ```
       function wpse83754_filter_pre_get_posts( $query ) {
           if ( $query->is_main_query() && is_page( $id ) ) {
               $query->set( 'post_type', array( 'category/mit-strom' ) );
           }
       }
       add_action( 'pre_get_posts', 'wpse83754_filter_pre_get_posts' );
       ```
   
    -  This reply was modified 5 years, 3 months ago by [Gustav](https://wordpress.org/support/users/4ever16/).
 *  Thread Starter [nicolasanderes](https://wordpress.org/support/users/nicolasanderes/)
 * (@nicolasanderes)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/random-order-blog-posts/#post-13964802)
 * Hey! [@4ever16](https://wordpress.org/support/users/4ever16/)
 * thanks a lot for your time, i really appreciate it…. I have now inserted the 
   codes, but unfortunately it still does not want to work…. Do I have to insert
   them at a certain place in Functions.php? As far as I know not really?
    -  This reply was modified 5 years, 3 months ago by [nicolasanderes](https://wordpress.org/support/users/nicolasanderes/).
    -  This reply was modified 5 years, 3 months ago by [nicolasanderes](https://wordpress.org/support/users/nicolasanderes/).
 *  [Gustav](https://wordpress.org/support/users/4ever16/)
 * (@4ever16)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/random-order-blog-posts/#post-13964850)
 * Well the problem is “/category/name”
 * Well hope someone else can help you.
 *  Moderator [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [5 years, 3 months ago](https://wordpress.org/support/topic/random-order-blog-posts/#post-13965315)
 * It’s entirely possible that the code works, but your caching plugin is not serving
   new HTML for each visit. Try disabling the batcache plugin. If that fixes it 
   and random order is more important than speed, disable caching on your home page.
 *  Thread Starter [nicolasanderes](https://wordpress.org/support/users/nicolasanderes/)
 * (@nicolasanderes)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/random-order-blog-posts/#post-13965400)
 * Thank you [@sterndata](https://wordpress.org/support/users/sterndata/) for your
   answer!
 * No, the website speed is more important to us after all, especially since it 
   is already slow…. If this is the only way, we will do without it.
    Likewise, 
   it would be important for us to keep the design and that rules out most plugins….:/
 *  [helvetica123](https://wordpress.org/support/users/helvetica123/)
 * (@helvetica123)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/random-order-blog-posts/#post-13966346)
 * [@nicolasanderes](https://wordpress.org/support/users/nicolasanderes/) HTML code
   on websites generally so lite when compare with css and js.May you can disable
   cache for only HTML to test and if there is no important slowing, you can continue
   without HTML cache and random feature.It is only advice

Viewing 15 replies - 1 through 15 (of 17 total)

1 [2](https://wordpress.org/support/topic/random-order-blog-posts/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/random-order-blog-posts/page/2/?output_format=md)

The topic ‘Random order blog posts’ is closed to new replies.

## Tags

 * [Blog](https://wordpress.org/support/topic-tag/blog/)
 * [order](https://wordpress.org/support/topic-tag/order/)
 * [posts](https://wordpress.org/support/topic-tag/posts/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 17 replies
 * 4 participants
 * Last reply from: [nicolasanderes](https://wordpress.org/support/users/nicolasanderes/)
 * Last activity: [5 years, 3 months ago](https://wordpress.org/support/topic/random-order-blog-posts/page/2/#post-13974172)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
