• iraq

    (@iraq)


    Why I can’t see the posts on the front page using this query?

    <?php $my_query = new WP_Query(‘category_name=posts&showposts=1’);
    while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate = $post->ID; ?>

    ——-Do Action———

    <?php $my_query = new WP_Query(‘category_name=posts&showposts=6’);
    $countposts = 0;
    while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate = $post->ID; ?>
    <?php if ($countposts == 0) : ?>

    ——-Do Action———

    Thanks in advance

Viewing 2 replies - 1 through 2 (of 2 total)
  • geoffe

    (@geoffe)

    One problem might be that you don’t have an endwhile statement in there to end the loop.

    I presume you are trying to achieve something like what is found in the example here:
    http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action

    That code:

    <?php $my_query = new WP_Query('category_name=featured&showposts=1');
    while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate = $post->ID;?>
    <!-- Do stuff... -->
    <?php endwhile; ?>
    <!-- Do other stuff... -->
    <?php if (have_posts()) : while (have_posts()) : the_post();
    if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
    <!-- Do stuff... -->
    <?php endwhile; endif; ?>

    The idea of assigning the do_not_duplicate variable the ID of the first post is so that the one post in the first section is checked in the second loop.
    if( $post->ID == $do_not_duplicate ) continue;

    …which means, if the post ID from the earlier loop of the first post is coming up in the second loop, continue and ignore it for this loop.

    Thread Starter iraq

    (@iraq)

    Thank you geoffe for the answer

    I will check it out again

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘What’s wrong with this query?’ is closed to new replies.