Exclude sticky posts at the top


In my theme I have this code to display the post and I want to exclude the sticky post at the top so that they regain a normal order.

$i = 1;
// 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 ">";

According to the wordpress [B]codex[/B] should I use the following code to perform this function but do not know how to use it.


What I have to do?

If people here cannot help, you should try the official Wordpress support forum instead.

Thanks, I already tried in the Wordpress support forum and they have told me this:


You may need to use a new WP_Query so that WordPress doesn’t think you are ‘poplulating’ the main query. Example:

  '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>
wp_reset_query();  // Restore global post data stomped by the_post().

Perhaps as they say should apply a new WP_Query but the truth is that my knowledge is rather limited and do not know how to do this.

There is no way to modify the existing WP_Query?

I’m desperate and do not know what to do.


If all else fails here, I suggest that you might want to head back in to the lion’s den, and enquire of the Wordpress forum for some details on how to apply the new WP_Query.

While we here know a lot about PHP, and we do have a generic CMS forum, there’s no better place for gaining the most effective help on Wordpress scripting than by going right to the source.

I know you’re right, the best help is always the source in this case Wordpress. I appreciate your help and I will continue looking for the solution … hope to get lucky!

By the way, if not much could be could change this thread and move it to generic CMS forum … can it be?