WordPress.org

Forums

WP Query - odd/even and post types (2 posts)

  1. MI
    Member
    Posted 1 year ago #

    Hi,

    I want that odd and even posts would be different post types in one loop. How can i make it work? Here is the test query, which i think should work with getting odd and even ones, but how can i attach different post type here?

    $args( 'post_type' => 'TYPE' );
    
    $query = new WP_Query( $args );
    
    <?php while (have_posts()): the_post() ?>
        <?php if ($wp_query->current_post % 2 == 0): ?>
            odd
        <?php else: ?>
            even
        <?php endif ?>
    <?php endwhile ?>

    Thanks

  2. Steven Jones
    Member
    Posted 1 year ago #

    You've performed a query but then just used the standard query for that post. Instead you should be doing this.

    <?php while ($query->have_posts()): $query->the_post() ?>
        <?php if ($query->current_post % 2 == 0): ?>

    Also, it looks like you have the odd and even conditions the wrong way around.

Topic Closed

This topic has been closed to new replies.

About this Topic