• Any ideas on what’s going on here and how to fix it? I’m using WordPress 3.2 and a variety of plug-ins, Category Checklist Tree being the only one that deals with categories, which is where my problem occurs. Note: when I deactivate Category Checklist Tree I still have the following problem.

    I have the following post category grandparent->parent->child structure

    In the classroom
    	First Grade
    		Aleph
    		Bet
    		Gimel
    	Second Grade
    		Aleph
    		Bet
    		Gimel
    	Third Grade
    		Aleph
    		Bet
    		Gimel
    	Fourth Grade
    		Aleph
    		Bet
    		Gimel

    When I run the following code:

    $ID = $wp_query->posts[0]->cat_ID;
    $postcat = get_the_category($ID);
    $cat = $postcat[0]->cat_ID;
    $thiscat = get_category($cat);
    print_r($thiscat);

    on a single page with a post categorized:

    In the classroom
    	Second Grade
    		Gimel

    I get:

    stdClass Object ( [term_id] => 44 [name] => Gimel [slug] => gimel-second-grade [term_group] => 0 [term_taxonomy_id] => 44 [taxonomy] => category [description] => [parent] => 28 [count] => 1 [object_id] => 765 [cat_ID] => 44 [category_count] => 1 [category_description] => [cat_name] => Gimel [category_nicename] => gimel-second-grade [category_parent] => 28 )

    Which is the result I’d expect and consider correct. However, when I run the same on a single page with a post categorized:

    In the classroom
    	First Grade
    		Gimel

    or

    In the classroom
    	Fourth Grade
    		Gimel

    I get:

    stdClass Object ( [term_id] => 63 [name] => First Grade [slug] => first-grade [term_group] => 0 [term_taxonomy_id] => 63 [taxonomy] => category [description] => [parent] => 26 [count] => 1 [object_id] => 760 [cat_ID] => 63 [category_count] => 1 [category_description] => [cat_name] => First Grade [category_nicename] => first-grade [category_parent] => 26 )

    Which is wrong: the [name] should be Gimel, the [slug] should be gimel-first-grade, etc.

    Noticing that both problem categories begin with “F”, I’ve run a test where I’ve changed the category “First Grade” to “Thirst Grade” and I then get the correct results: Gimel and gimel-first-grade. I’ve run additional tests renaming the category to “G”, “F”, “E”, “D”, “C”, “B” & “A” and each generates the WRONG result: First Grade & first-grade. When I change the category name first letter to any letter other than A, B, C, D, E, F, & G I get the correct result. Also note that when I run this code on a single page with a post categorized:

    In the classroom
    	First Grade (or Fourth Grade)
    		Aleph (or Bet)

    I get the correct result: [name] is Aleph (or Bet) and [slug] is correct as well.

    I’ve looked at the database and all of the category parent/child relationships are correct.

    It appears that there’s some sort of bug with get_the_category or get_category. Any ideas on what’s going on here and how to fix it?

    Thanks in advance.

Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Bug with WordPress get_the_category or get_category?’ is closed to new replies.