Support » Fixing WordPress » query odd (or even) custom post

  • Resolved Antonello

    (@lellocaravano)


    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!

Viewing 1 replies (of 1 total)
  • Antonello

    (@lellocaravano)

    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!

Viewing 1 replies (of 1 total)
  • The topic ‘query odd (or even) custom post’ is closed to new replies.