title: How to display random posts in one single category in wordpress
body: <p>I need to be able to randomize the posts in one single category. I have the following code at the moment in functions.php:</p>
  
  <pre><code>    &lt;?php
  
  add_action( 'pre_get_posts', 'generate_random_category_posts', 100 );
  function generate_random_category_posts( $query ) {
      $catto = get_queried_object();
      if ( $query-&gt;is_category() &amp;&amp; $query-&gt;is_main_query() &amp;&amp; $catto-&gt;term_id = 9 ) {
          $query-&gt;set( 'orderby', 'rand' );
      }
  }
  
  ?&gt;
  </code></pre>
  
  <p>But the problem is that it randomizes posts in all the categories. Can someone please help me with this and tell me how I can randomize posts only in category number 9?</p>