title: How to sort the result of wp_query
body: <p>I'm trying to sort the results of wp_query, i want to sort it by different parameters without make the query again. I have something like that:</p>
  
  <pre><code>$the_query = new WP_Query( $args );
  </code></pre>
  
  <p>And i want to sort $the_query, WP_Query returns a structure like that: </p>
  
  <pre><code>$the_query-&gt;posts[0]-&gt;title; 
  </code></pre>
  
  <p>So, I want to sort all the elements by 'title' for example. I tried this:</p>
  
  <pre><code>usort($the_query-&gt;posts, function($a, $b) {
     return $a['title'] - $b['title'];
  });
  </code></pre>
  
  <p>I want to sort after i do the query. Is because i want tosort many times and i dont want to do the query every time i want to sort </p>
  
  <p>SOLUTION</p>
  
  <p>This returns Fatal error: Cannot use object of type WP_Post as array</p>
  
  <pre><code>usort($the_query-&gt;posts, function($a, $b) {
     return $a['title'] - $b['title'];
  });
  </code></pre>
  
  <p>This is because the structure of the array is like that:</p>
  
  <pre><code>$the_query-&gt;posts[0]-&gt;title; 
  </code></pre>
  
  <p>so you have to change <code>$a['title'] - $b['title']</code>  for <code>$a-&gt;title - $b-&gt;title</code>
  and using the answer of Pieter Goosen the Final result is:</p>
  
  <pre><code>usort($the_query-&gt;posts, function($a, $b) {
      return strcasecmp( 
              $a-&gt;title, 
              $b-&gt;title
          );
  });
  </code></pre>
  
  <p>Thank for all</p>