I have a simple site that shows one random post when you reach it. This post then has a link below it that, when clicked, will pull in another random post to that homepage, excluding all posts from the category that the current post is in.

Eg. A post from category 'Bikes' is shown. Below it is a link that needs to replace that post with another random post from all the categories excluding the posts in 'Bikes'

I am finding it easy to find code for excluding a set category but i can't find a way to read what post category is shown on the page and exclude only that.

I would greatly appreciate any advice.

WordPress Version 3.1

1 Answer 1


wp_get_post_categories() (Codex reference) is used to get the categories for a post

  • I'm not trying to get the categories for a post, I'm trying to get all the posts in a category but exclude the current post
    – user983248
    Commented May 23, 2012 at 12:38
  • @user983248 then you should ask a separate question.
    – anu
    Commented May 23, 2012 at 14:17
  • Hi sorry, but I had two browsers windows and I got confused, This is not even my question. I was trying to reply to a comment on a question of my own. Sorry anu :)
    – user983248
    Commented May 23, 2012 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.