What I need: show random post except current post for custom post type
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
Previously I wrote
Question now changed to
question, but still results the same
Questionshould probably be
questionalso results same.
$post->IDhowever giving wrong number to custom post type but works fine on Post & Page