WordPress.org

Ready to get started?Download WordPress

Forums

query_posts() and pagination issues (9 posts)

  1. Fresh321
    Member
    Posted 3 years ago #

    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"

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    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

  3. Fresh321
    Member
    Posted 3 years ago #

    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 :]

  4. Fresh321
    Member
    Posted 3 years ago #

    Anyone else? :]

  5. chinmoy
    Member
    Posted 3 years ago #

    try this once

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

  6. Fresh321
    Member
    Posted 3 years ago #

    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 :]

  7. chinmoy
    Member
    Posted 3 years ago #

    Sorry! I mistake something

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

    Try it once.

  8. chinmoy
    Member
    Posted 3 years ago #

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

  9. Fresh321
    Member
    Posted 3 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic