• Resolved werlisa

    (@werlisa)


    Hi,

    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.

    <?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 ">"; ?>

    I know I have to use this code but not as you insert it into the existing code.

    query_posts('caller_get_posts=1');

    What I have to do?

Viewing 9 replies - 1 through 9 (of 9 total)
  • $posts = query_posts($query_string . '&orderby='.$orderby.' meta_key='.$key.'&order='.$order.'&caller_get_posts=1');}

    Note–I left the ending brace } there also

    Thread Starter werlisa

    (@werlisa)

    Thank You, I changed as you say but everything remains the same and continue to sticky posts at the top … I do not understand why.

    Thread Starter werlisa

    (@werlisa)

    I’ll be back to share the code because they do not see anything good in my first post ..

    <?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 ">";
    ?>
    Thread Starter werlisa

    (@werlisa)

    $posts = query_posts($query_string . '&orderby='.$orderby.' meta_key='.$key.'&order='.$order.'&caller_get_posts=1');

    Thank You, I changed as you say but everything remains the same and continue to sticky posts at the top … I do not understand why.

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

    <?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().
    ?>

    Thread Starter werlisa

    (@werlisa)

    Thanks again for your answer, perhaps as you 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?

    Thread Starter werlisa

    (@werlisa)

    Can anyone help me? plsss!!

    Thread Starter werlisa

    (@werlisa)

    Thread Starter werlisa

    (@werlisa)

    The above link is not the answer, sorry:

    https://www.ads-software.com/support/topic/392563?replies=10

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Exclude sticky posts at the top’ is closed to new replies.