Wrangling WordPress–need help

As many of you know I’m doing some WordPress work and I’m bumping heads with the same issue over and over again… so I’m turning to my very smart, very resourceful and very helpful wordpress friends who I’m happy to suck up to in order to get help with the bane of my existence – CATEGORIES!

Mess of Flags

Here’s the thing: I want a predictable way to know which category is going to show up dominate for a post if I assign 2 categories. Clarification: which category will be used in permalink if 2 are assigned.

WordPress sucks at this and seems to be aggressively inconsistent or at least if it's consistent I can't figure out the logic.  (I will concede that it’s possible I suck, but my math degree does imply I have some skill in the logic area. (Math degree → logic skilz, Math degree \not\to spelling skilz)

An example:  I have a post about a dish, I have things set up to show the post's category in the excerpt and to have it used in the permalink  filed under that category, so it’s important I can control which category dominates if there are 2 assigned.   Say a post about Poutine (category: Dish) where I recommend 2 restaurants (so I also want it to show up in the category Reco).

I want the permalink to use Dish not Reco.

Since Reco is a new category I added today, based on what I thought WP logic was (assign dominate category by oldest added to WP->;newest category) Dish should dominate. It doesn't.   (But the reverse logic has been disproven in previous posts) It's not alphabetical. It's not hierarchical (where highest in the category hierarchy dominates).  It's getting me down.

So… any way we can assign a "dominant category"? Essentially force WP's hand and use what I tell it to use?

I do this for indexing in CheapEats (I know, totally different tech) but it's a great way to avoid your tech making your content producer it's bitch.

(and yes, I am posting this on a typepad blog. Shhhh)

Alexa Clark

Alexa is a digital marketer and author with over 20 years in digital & interactive communications in the food and tech industries. Alexa's CheapEats Restaurant Guides, for both Toronto & Ottawa, were Canadian best sellers. She is a recognized authority on social media and has been named one of Canada's 20 Leading Women in Social Media.

5 thoughts on “Wrangling WordPress–need help

  • February 8, 2012 at 6:43 pm
    Permalink

    Why don’t you just edit the post slug and leave the category out of the URL? Categories in URLs sound like a good idea but as every story ever told about them points out, it just isn’t something actually makes sense. You need a one-category-per-post rule if you want it to be consistent.
    There a probably plugins that firm up the situation, but do you want to depend on a plugin for your URLs? I wouldn’t.

    Reply
  • February 9, 2012 at 11:52 am
    Permalink

    Thanks Jeremy, excellent points.
    The other problem is that we’re using the category (the first one returned in the array) to display in the header of the post.
    So I need to be able to control which one will be returned first.
    So the questions is:
    1. is there somewhere in the codex that explains how categories are ordered when they are returned
    in the category arg?
    and
    2. is there a way to assign a priority order? So if I want Dish to always be returned first if it’s one of the categories assigned, that it’s always returned first?

    Reply
  • February 9, 2012 at 1:21 pm
    Permalink

    I haven’t explored the code yet, but this article states that categories are assigned to permalinks based on the category id. That makes sense to me, considering other WordPress code that I’ve reviewed.
    http://homebizpal.com/blogging/wordpress/understanding-wordpress-permalinks/
    So, the order in which you add the categories would determine which one is selected.
    Although I can’t recommend a specific permalink plugin, it sounds like you need the fine control that a plugin could provide.

    Reply
  • February 9, 2012 at 1:26 pm
    Permalink

    Hi @Swhitley, I thought similarly and deleted all my categories, adding them back in the priority order I wanted. Didn’t work. Thus the frustration above.
    Thanks thought!

    Reply
  • February 13, 2012 at 3:46 pm
    Permalink

    Okay, we’ve dug deeper and it seems our categories aren’t being returned in Category ID order, but in alphabetical order.
    Which seemed random, but in fact is not random at all.

    Reply

What do you think?