title: query_posts() should be avoided?
body: <p>I am reading that <code>query_posts()</code> should be avoided in favor of <code>wp_query()</code> and <code>pre_get_posts()</code>. I am not confident with messing with the Loop and do not fully understand the codex.</p>
  
  <p>Does the code below use <code>query_posts()</code> ? If yes and since <code>query_posts()</code> should be avoided, can you suggest a method that does not use <code>query_posts()</code> but still accomplish the same thing?</p>
  
  <p>This code in <code>functions.php</code> is used to sort posts by random or by price. </p>
  
  <pre><code>function my_custom_query($query){
   if ( $query-&gt;is_home() &amp;&amp; $query-&gt;is_main_query() ) {
  
     $sort= $_GET['sort'];
  
     if($sort == "pricelow"){
       $query-&gt;set( 'meta_key', 'price' );
       $query-&gt;set( 'orderby', 'meta_value_num' );
       $query-&gt;set( 'order', 'ASC' );
      }
  
    if($sort == "random"){
       $query-&gt;set( 'orderby', 'rand' );
      }
  
   }
  }
  add_action( 'pre_get_posts', 'my_custom_query' );
  </code></pre>
  
  <p>.<br>
  Link A (Random) and Link B (Price) are posted in my menu by using this code. Thus the visitor to the website can sort the posts simply by clicking a link.</p>
  
  <pre><code>&lt;a href="http://website.com/?sort=A"&gt;Random&lt;/a&gt;
  &lt;a href="http://website.com/?sort=B"&gt;Price&lt;/a&gt;
  </code></pre>