Title: New Query Post
Last modified: August 19, 2016

---

# New Query Post

 *  Resolved [werlisa](https://wordpress.org/support/users/werlisa/)
 * (@werlisa)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/new-query-post/)
 * Hello everyone,
 * According MichaelH instructions should create a new Query Post to solve the problem
   of sticky posts at the top of my index, I want these sticky posts do not appear
   anchored to the top of my index and disappear in order of publication but are
   not as do so.
 * This is the Query existing post in my topic.
 *     ```
       <?php
       $i = 1;
       if(!empty($_GET['sort']))
       {
       $orderby=trim($_GET['sort']);
       $order=trim($_GET['order']);
       $key=trim($_GET['key']);
       // create the sort by injection
       $posts = query_posts($query_string . '&orderby='.$orderby.'&meta_key='.$key.'&order='.$order.'');
       }
       if (have_posts()) : ?>
       <?php while (have_posts()) : the_post(); ?>
       <?php if ($i % 2 == 0) { $alt = " class=\"alt\""; } else { $alt = " class=\"no\""; } echo "<div" . $alt;
       if (is_sticky()) { echo " id='sticky' "; } echo ">";
       ?>
       ```
   
 * And this is the example again proposed by MIchaelH Post Query.
 *     ```
       <?php
       $args=array(
         'meta_key'=>$key,
         'orderby'=> $orderby,
         'order' => $ordr,
         'post_type' => 'post',
         'post_status' => 'publish',
         'posts_per_page' => -1,
         'caller_get_posts'=> 1
       );
       $my_query = null;
       $my_query = new WP_Query($args);
       if( $my_query->have_posts() ) {
         while ($my_query->have_posts()) : $my_query->the_post(); ?>
           <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
           <?php
         endwhile;
       }
       wp_reset_query();  // Restore global post data stomped by the_post().
       ?>
       ```
   
 * Someone should know how to do this job?
 * Regards

Viewing 9 replies - 1 through 9 (of 9 total)

 *  [Shane G.](https://wordpress.org/support/users/shane-g-1/)
 * (@shane-g-1)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/new-query-post/#post-1479369)
 * Hi,
 * Refer this article:
 * [http://codex.wordpress.org/Function_Reference/query_posts](http://codex.wordpress.org/Function_Reference/query_posts)
 * Also check with this plugin:
 * [http://wordpress.org/extend/plugins/query-posts/](http://wordpress.org/extend/plugins/query-posts/)
 * Thanks,
 * Shane G.
 *  Thread Starter [werlisa](https://wordpress.org/support/users/werlisa/)
 * (@werlisa)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/new-query-post/#post-1479388)
 * Thanks for the reply.
    I tried the query post plugin and it works wonderfully
   but it is a widget and not affect the overall outcome of the site, continuing
   the sticky posts anchored to the top of the site.
 * As for the wordpress codex I’ve consulted to find the solution “caller_get_posts
   =1” but this seems not to work on my site.
 *     ```
       <?php
       $i = 1;
       if(!empty($_GET['sort']))
       {
       $orderby=trim($_GET['sort']);
       $order=trim($_GET['order']);
       $key=trim($_GET['key']);
       // create the sort by injection
       $posts = query_posts($query_string . '&orderby='.$orderby.'&meta_key='.$key.'&order='.$order.'&caller_get_posts=1');
       }
       if (have_posts()) : ?>
       <?php while (have_posts()) : the_post(); ?>
       <?php if ($i % 2 == 0) { $alt = " class=\"alt\""; } else { $alt = " class=\"no\""; } echo "<div" . $alt;
       if (is_sticky()) { echo " id='sticky' "; } echo ">";
       ?>
       ```
   
 * I do not know what else I can do … my head will explode! 😛
 *  Thread Starter [werlisa](https://wordpress.org/support/users/werlisa/)
 * (@werlisa)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/new-query-post/#post-1479435)
 * Can anyone help me?
 *  [Safirul Alredha](https://wordpress.org/support/users/zeo/)
 * (@zeo)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/new-query-post/#post-1479498)
 * May I know what’s wrong with MichaelH solution?
 *  Thread Starter [werlisa](https://wordpress.org/support/users/werlisa/)
 * (@werlisa)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/new-query-post/#post-1479505)
 * Hi Zeo, MichaelH proposed solution according to all the references I have consulted“
   including wordpress codex” is the correct solution. The problem is that this 
   solution does not work on my site, I think the query post on my site makes it
   more difficult to make sticky posts are not anchored at the top and in my opinion
   this part of the code is to blame that:
 *     ```
       $i = 1;
       if(!empty($_GET['sort']))
       {
       $orderby=trim($_GET['sort']);
       $order=trim($_GET['order']);
       $key=trim($_GET['key']);
       ```
   
 * Have an idea?
 * Regards
 *  [Safirul Alredha](https://wordpress.org/support/users/zeo/)
 * (@zeo)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/new-query-post/#post-1479508)
 * Not tested but do have a try.
 *     ```
       <?php
       $i = 1;
       if ( !empty($_GET['sort']) ) {
         $orderby = trim($_GET['sort']);
         $order = trim($_GET['order']);
         $key = trim($_GET['key']);
   
         query_posts($query_string . '&caller_get_posts=1&orderby=' . $orderby . '&meta_key=' . $key . '&order=' . $order);
       }
   
       if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
       <?php
         if ( $i % 2 == 0 ) { $alt = " class=\"alt\""; } else { $alt = " class=\"no\""; }
         echo "<div" . $alt;
         if ( is_sticky() ) { echo " id='sticky' "; } echo ">";
       ?>
   
         <?php the_title(); ?>
   
       <?php endwhile; endif;
         wp_reset_query();
       ?>
       ```
   
 *  Thread Starter [werlisa](https://wordpress.org/support/users/werlisa/)
 * (@werlisa)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/new-query-post/#post-1479509)
 * There is no way that goes well,
 * I tried your suggestion and everything remains the same, sticky posts continue
   to be anchored at the top of the index…this is a headache!
 * Thanks for your help Zeo
 *  [Safirul Alredha](https://wordpress.org/support/users/zeo/)
 * (@zeo)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/new-query-post/#post-1479510)
 * Oops, try change this:
 *     ```
       query_posts($query_string . '&caller_get_posts=1&orderby=' . $orderby . '&meta_key=' . $key . '&order=' . $order);
       }
       ```
   
 * to this:
 *     ```
       }
         query_posts($query_string . '&caller_get_posts=1&orderby=' . $orderby . '&meta_key=' . $key . '&order=' . $order);
       ```
   
 *  Thread Starter [werlisa](https://wordpress.org/support/users/werlisa/)
 * (@werlisa)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/new-query-post/#post-1479512)
 * Works! It seems incredible what you can do a little change .. 🙂
 * Thank you very much for your help, especially for you Zoe.
 * I have visited your blog Zoe, and there is a very interesting aspect that I put
   into practice successfully. This is limiting the number of posts by category 
   by adding this feature:
 *     ```
       function limit_posts_per_page() {
       	if ( is_category() )
       		return 2;
       	else
       		return 5; // default: 5 posts per page
       }
       add_filter('pre_option_posts_per_page', 'limit_posts_per_page');
       ```
   
 * I wonder if you can do the same with the results of the search … is it possible?
 * By the way, I opened another question about it here:
 * [http://wordpress.org/support/topic/393462?replies=1](http://wordpress.org/support/topic/393462?replies=1)
 * Regards!

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘New Query Post’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 9 replies
 * 3 participants
 * Last reply from: [werlisa](https://wordpress.org/support/users/werlisa/)
 * Last activity: [16 years, 1 month ago](https://wordpress.org/support/topic/new-query-post/#post-1479512)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
