WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am developing a custom post type which shows releated posts which are within the category which is working perfect but I cant seem to get the right query to make it not show the current post which is being viewed.

The code I have at present is:

$args = array(
        'post_type' => 'custompostname',
        'tax_query' => array(
                'taxonomy' => 'custompostname-categories',
                'field' => 'id',
                'terms' => $categoryIDs
        'post__not_in' => $post->ID,
        'posts_per_page' => 20
    $q = new WP_Query($args);

Could anyone please shed some light on why this is not working.

If I remove the:

'post__not_in' => $post->ID,

It works apart from it shows the post which is on the page already


share|improve this question
I've had similar trouble once, did u try 'post__not_in' => array( $post->ID) instead ? – webdwall Jul 28 '13 at 10:06
Yes its there please see :) – Robert Jul 28 '13 at 10:07
@webdwall sorry did not read it correctly, yes adding an array works :) thank you – Robert Jul 28 '13 at 10:12
No, i mean, instead of 'post__not_in'=>$post->ID, did u try taking post id in an array, even though its just one. like 'post__not_in' => array( $post->ID) – webdwall Jul 28 '13 at 10:13
Ok, if it works then please mark the question as solved and you can upvote my comment as well if you want :) – webdwall Jul 28 '13 at 10:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.