Juggling Taxonomy with Pathauto

(2 minute read)

Today I was working on a site when I noticed my node paths were incorrect for some of my nodes. Now I heavily use Pathauto in conjunction with Taxonomy to define my paths for everything on the site and this issue hasn’t come up before. I swear, I didn’t change my Pathauto rules ([termpath-raw]/[title-raw]), so what changed?

After looking at the nodes that have the incorrect path and nodes that have the correct paths I figured out that Pathauto was selecting one of my other taxonomies on the node. The nodes I was working with had multiple Taxonomy Categories that applied to it. Pathauto was simply taking the lightest category that was filled out and using that. So for my nodes that were correct, the first category that was filled out was the one I was planning on using for the path. The incorrect nodes had another category filled out before the one I wanted. The solution was pretty simple. Adjust the weights of my Taxonomy Categories. I made the category -10 that I wanted to always affect the path of the node. That way it will always be first in my listing on the node creation/edit page. After I adjusted the weight I went into the content view and regenerated the aliases for my nodes (Make sure you adjust your Pathauto settings to Create New Alias, Delete Old - or else you’ll get multiple path aliases which will cause the old alias to still work).

Categories: