Make WordPress Core

Opened 14 years ago

Closed 13 years ago

Last modified 13 years ago

#14669 closed defect (bug) (duplicate)

get_categories returns only after page reload all cats

Reported by: christian_gnoth's profile christian_gnoth Owned by:
Milestone: Priority: normal
Severity: major Version: 3.0.1
Component: Cache API Keywords:
Focuses: Cc:


I am using in a plugin the following script:

  //  check if default cat exists
  if ( !get_cat_ID('ImportFit') ) 
    wp_create_category( 'ImportFit' );

  $categories = get_categories(array('hide_empty' => false));

with a var_dump on $categories I can see, that the created category is returned only after one page reload. in the category view in the backend the created cat is visible.

Change History (6)

#1 @christian_gnoth
14 years ago

  • Severity changed from normal to major

#2 @dd32
14 years ago

  • Component changed from General to Cache

This condition is only hit if 2 conditions are met:

  • The category list has been queried in the pageload already
  • The get_categories() call is made within 1 second of the category being created. (ie. time(creation) == time(2ndquery))

This is not unique to Categories, It applies to all terms.

The cause is related to the 'last_changed' cache key used in the Taxonomy API it appears to me.

#3 @filosofo
13 years ago

  • Milestone changed from Awaiting Review to Future Release

#4 follow-up: @christian_gnoth
13 years ago

  • Version changed from 3.0.1 to 3.2.1

still with version 3.2.1 I have the same problem. During plugin activation action I have the following code:

  //  check if default cat exists
  if ( !get_cat_ID('Support Tickets') ) 
    $cat_id = wp_create_category( 'Support Tickets' );
    $cat_id = wp_create_category( 'New Tickets', $cat_id );

In the posts->catgories section I get only the "Support Tickets" category, the child category is not listed.

#5 in reply to: ↑ 4 @scribu
13 years ago

  • Milestone Future Release deleted
  • Resolution set to duplicate
  • Status changed from new to closed

This is just another symptom of #14485

#6 @SergeyBiryukov
13 years ago

  • Version changed from 3.2.1 to 3.0.1

Restoring the initial reported version.

Note: See TracTickets for help on using tickets.