0

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?

2

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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