WordPress.org

Support

Support » How-To and Troubleshooting » query_posts() and pagination issues

query_posts() and pagination issues

  • I know this has been asked and answered many times, but simply I cant get this to work. I have tried all the solutions posted here and over Internet, but they not work in my case 🙂

    I want to display some posts with specific tags with custom time line.
    Right now my code looks like this:

    <div class="someclass">
    <?php function filter_where($where = '') {
    $where .= " AND post_date >= '2010-01-01' AND post_date < '2010-08-01'";
    return $where;
    }
    add_filter('posts_where', 'filter_where');
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('tag=tagone,tagtwo&paged=$paged');?>
    <?php
    $i=0;
    if (have_posts()) : while (have_posts()) : the_post(); $i++ ?>
    <?php $thumb = get_post_meta($post->ID, 'thumbnail', $single = true); ?>
    <p> <?php echo $i.'. '; the_title(); ?> </p>
    <?php endwhile; endif; ?>
    </div> <!--content-block putopis end-->
    <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>
    <?php wp_reset_query(); ?>

    Code above work as it should. It display posts from 2010-01-01 to 2010-08-01, which have tags “tagone” and “tagtwo”

Viewing 8 replies - 1 through 8 (of 8 total)
  • Moderator Michael

    @alchymyth

    Forum Moderator

    try to use either:
    query_posts("tag=tagone,tagtwo&paged=$paged");
    or
    query_posts('tag=tagone,tagtwo&paged=' . $paged)

    reason:

    be careful that you can do this only inside double quotes. if you use a statement like that:

    echo ‘you have $msg_num messages! ‘ ;

    you ‘ll get html output exactly as in the quotes:

    http://phphowto.blogspot.com/2006/12/concatenate-strings.html

    Thanks for the answer alchymyth.
    I have tried this before, also not work..

    The page numbers are displayed, but they lead just to the 404 page :]

    Anyone else? :]

    try this once

    query_posts($query_string . 'tag=tagone,tagtwo&paged='.$paged);

    It not work at all with that code, post titles and pagination are not displayed.

    When i remove $query_string, then post title work, but not pagination.

    Thanks for taking your time to reply :]

    Sorry! I mistake something

    global $query_string;
    query_posts($query_string . '&tag=tagone,tagtwo&paged='.$paged);

    Try it once.

    also <?php rewind_posts();?> instead of <?php wp_reset_query(); ?>

    Hello chinmoy29!

    Again not work. Anyway I ll solve this in another way. Its not so smart, but I don’t have much time for thinking :]

    Thank you again for trying to help me :]

    All the best!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘query_posts() and pagination issues’ is closed to new replies.