• Hi,

    Just wanted to ask whether anyone has seen or experienced this issue.

    I’m just updating a website for a customer that moved over to use from another developer. It was a website which was quite strangely coded.

    I’m not really sure how it was coded or how it was changed. I saw the functions.php and everything seems normal there. There does not seem to be any query_posts or WP_Query out of place. And the ones which use query_posts have a wp_reset_query() after the block.

    The issue is that when I access the loop only the 2nd item is output.

    I did a print_r($posts) and it seemed fine (all items are output) but when I did the loop syntax if (have_posts() : while (have_posts, etc. only the 2nd item comes out. So essentially I have to do a manual the_title() before the loop to get the first item, then run the loop to get the 2nd item.

    E.g.

    the_title(); //output first item
    
    /* output all items after first item */
    <?php if( have_posts() ) : while ( have_posts() ) : the_post(); ?>
            <h3><a href="<? the_permalink(); ?>"><? the_title(); ?></a></h3>
    <? endwhile; endif; ?>

    Anyone seen this before or experienced this? Would love to get some feedback because I’m not sure how it’s been done.

    Is there any other place where things could be changed to do this?

Viewing 1 replies (of 1 total)
  • Thread Starter exo_duz

    (@exo_duz)

    Just found out the issue.

    The previous programmer does a the_post() at the very top of the header file which in effect gets the first post outside the loop.

    Not really too sure why he did it this way but it’s good that the issue was found.

Viewing 1 replies (of 1 total)
  • The topic ‘WordPress loop issue (1st item outside and the rest inside the loop)’ is closed to new replies.