Ticket: #36916 Status: CLOSED Average Speed: 3.0 Days
public
Cancel

“Category Selection”

  • Jai Ketteridge
    http://www.directweld.com.au/weld/multi/lincoln-electric-flextec-450-multi/

    Hi there, I have a problem with your theme. I've noticed that on the particular post above that it doesnt appear to categorise properly and display the correct category in the fold over on the top right hand side of the image. To put it into perspective, it has categories associated with it, 1) HIRE (ID 99999), 2) Multi (ID 10300) & Lincoln Electric (ID 90100). In theory this should infact show the word Multi but it keeps showing HIRE. Even if I make a new post with the same 3 categories I get the same result! I had the same issue when the same named categories had different IDs. I have 3 other blog posts which are working as expected (WELD, HIRE, DIESEL as categories).

    Please help
    Thank you, and love the theme!

    3:01 on March 6, 2013

  • Philip Newcomer
    Hi,

    That is happening because when there are multiple categories assigned to the post, there is no way for WordPress to know which one you want to use. So the theme will choose the first category it finds, alphabetically. Unfortunately, there is no simple way to choose which category to be used as the category label.

    3:01 on March 7, 2013

  • Jai Ketteridge
    Thanks Philip. I was led to believe that category prodominance was selected by the category ID. Can this be changed somehow? Thank you!

    3:01 on March 7, 2013

  • Jef Vantongerloo
    The category with the lowest id is selected.
    You can give primary categories a low id, so they get selected.

    Unfortunately you can only do this by editing the database.
    So backup your database first!

    Queries:
    UPDATE `gs_terms`
    SET `term_id` = 10
    WHERE `term_id` = 5812;

    UPDATE `gs_term_taxonomy`
    SET `term_id` = 10
    WHERE `term_id` = 5812;

    UPDATE `gs_term_taxonomy`
    SET `term_taxonomy_id` = 10
    WHERE `term_taxonomy_id` = 5812;

    UPDATE `gs_term_relationships`
    SET `term_taxonomy_id` = 10
    WHERE `term_taxonomy_id` = 5812;

    3:01 on March 7, 2013

  • Jai Ketteridge
    Looking at Gonzo theme here - http://www.olliemccarthy.com/themes/gonzo/?cat=4

    News is Category ID 4. All the other news items are showing different category names with higher category IDs. How did you guys do that? A business post with category id 104 is there, then America with ID 13 and Opinion is 48. But Philip if I go by your advice of alphabetical wouldnt it hold true then that the opinion post with the sheep on it would infact show "News" over the thumbnail image instead of Opinion? But it doesnt... so Im confused, especially since opinion is after News both alphabetically and by Category ID?

    Thank you

    3:01 on March 8, 2013

  • Jef Vantongerloo
    Those categories are nested:
    - News
    -- America
    -- Asia
    -- Europe
    -- Opinion

    3:01 on March 8, 2013

  • Jai Ketteridge
    Thanks for that, so because they are nested they sort themselves out..

    So if I have selected say 3 categories for a post, and each of those categories have no parent (so they are top level) how does wordpress then figure out which one to use? Again, alphabetically for this and no reference to the ID?

    a post for me may have categories HIRE (ID 99999), Multi (ID 10300) & Lincoln Electric (ID 90100) and it selects Hire every time! Considering Multi is the lowest ID i really want it to take that!!! First World Problems! Wordpress should let you select a default category!

    3:01 on March 8, 2013

  • Jef Vantongerloo
    As stated here:

    "When you assign multiple categories to a post, only one can show up in the permalink. This will be the lowest numbered category (see Manage Categories). The post will still be accessible through all the categories as normal."
    http://codex.wordpress.org/Using_Permalinks

    3:01 on March 8, 2013

  • Philip Newcomer
    If you look at the code in the loop modules, you'll see this for getting the category:$category = get_the_category();and laterecho $category[0]->cat_name;Whatever category is the first item in the array that WordPress returns will be used.

    It is possible to filter get_the_categories (http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/category-template.php#L86) and to replace that array with whatever you want. So you could add a custom field to the post containing the ID of the category you want to use, and then in your filter you can use that to return the specified category instead of the default WordPress output.

    3:01 on March 12, 2013

Updating...