WordPress.org

Forums

[resolved] query odd (or even) custom post (2 posts)

  1. Antonello
    Member
    Posted 2 years ago #

    Hi!
    I have this query:

    <?php 
    
    	$args = array( 'post_type' => 'custompost', 'posts_per_page' => -1 );
    	$loop = new WP_Query( $args );
    
    	 while ( $loop->have_posts() ) : $loop->the_post(); 
    
    	 ?>

    How can I get only the odd posts?

    Thank you all!

  2. Antonello
    Member
    Posted 2 years ago #

    ok resolved with

    <?php 
    
    	$c = 0;
    
    	$args = array( 'post_type' => 'custompost', 'posts_per_page' => -1 );
    	$loop = new WP_Query( $args );
     while ( $loop->have_posts() ) : $loop->the_post();
    		  if($c % 2 == 0) :
    
    	 ?>
    //showpost
    																		<?php
    																	endif;
    																		$c++;
    																endwhile;																	?>

    and of course

    if($c % 2 != 0) :

    in the other query!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags