WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 have a post that belongs to two categories (Drinks, Food).

The post appears on category pages under /category/drinks and /category/food

When I click on the post under category archive /category/drinks it takes me to a post page that's in /food/

Is there any way to solve this in a way that the post stays in the same category?

share|improve this question
up vote 2 down vote accepted

If the template is using the permalink when generating the posts, it retrieves all the categories for a given post and then grabs the first category it gets after sorting them by Id.

I see two ways around this:

  1. If you want to recreate your categories with the preferred order, then you should be set. However, if you have a lot of posts in the system, this would be a hassle.

  2. Modify the template to generate your own links. When retrieving the category for the link, if multiple exist, you'll want to use the one that matches the category of the URL you are currently viewing the page in. You can use the source code of the get_permalink method as a way to get started.

share|improve this answer

Your Answer


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

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