• Resolved werlisa

    (@werlisa)


    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)
  • Thread Starter werlisa

    (@werlisa)

    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

    (@werlisa)

    Can anyone help me?

    May I know what’s wrong with MichaelH solution?

    Thread Starter werlisa

    (@werlisa)

    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

    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

    (@werlisa)

    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

    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

    (@werlisa)

    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:

    https://www.ads-software.com/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.