WordPress.org

Ready to get started?Download WordPress

Forums

Notice: Undefined variable: i in debug mode (3 posts)

  1. incoe
    Member
    Posted 1 year ago #

    Hello,

    i get Notice: Undefined variable: i on line 19 which reference to this code

    <?php if (have_posts()) : while(have_posts()) : $i++; if(($i % 2) == 0) : $wp_query->next_post(); else : the_post(); ?>

    any ideas how to fix that?

    Thanks in advance

  2. Andrew
    Forum Moderator
    Posted 1 year ago #

    Try;

    <?php
     $i = 0;
     if (have_posts()) : while(have_posts()) : $i++; if(($i % 2) == 0) : $wp_query->next_post(); else : the_post();
    ?>

    You may want to change the zero to one.

  3. incoe
    Member
    Posted 1 year ago #

    Thanks @andrew works fine with 0, when i put 1 it repeats post number 2 twice.

    Thanks for your help :)

Topic Closed

This topic has been closed to new replies.

About this Topic