Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.