What I need: show random post except current post for custom post type Question
In below codes, the exclusion doesn't works. It simply show any post including current post.
<?php
$my_query = new WP_Query( array('showposts' => '8', 'post_type' => 'question', 'post__not_in' => array( $post->ID ), 'orderby' => 'rand'));
while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
<a href="<?php the_permalink(); ?>"><?php the_title() ?></a><br>
<?php endwhile; ?>
If I change the Question
to be Page
, it works for Page. If remove the Question
, it works for Post.
I guess it must be something I missed if I want to make it works for custom post type
Update:
Previously I wrote Question
now changed to question
, but still results the same
Question
should probably bequestion
Question
toquestion
also results same.$post->ID
however giving wrong number to custom post type but works fine on Post & Page