• If the user is currently reading post ID 33, I’d like my loop below to exclude that post ID.

    <?php
    $post_list = array(46,17,33,41,43);
    foreach( $post_list as $post_id ) :
    query_posts('p='.$post_id);
    while (have_posts()) : the_post();
    ?>
    
        <?php the_title(); ?>
    
    <?php
    endwhile;
    wp_reset_query();
    endforeach;
    ?>

    I’ve come across the 'post__not_in' => array($this_post) argument but my loop needs to specifically display in the order of 46,17,33,41,43 so I can’t use the normal loop I usually use.

    Thanks in advance for any help

Viewing 1 replies (of 1 total)
  • How making a condition to eliminate #33 ?

    <?php
    $post_list = array(46,17,33,41,43);
    foreach( $post_list as $post_id ) :
    	$current_post = ( get_the_ID() != '' ) ? get_the_ID() : '';
    	if ( $post_id !== $current_post ) :
    		query_posts('p='.$post_id);
    		while (have_posts()) : the_post();
    			?>
    			    <?php the_title(); ?>
    			<?php
    		endwhile;
    		wp_reset_query();
    	endif;
    endforeach;
    ?>

    I haven’t tested it.

Viewing 1 replies (of 1 total)
  • The topic ‘Query specific set of posts but exclude current post’ is closed to new replies.