WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 3 years ago

Last modified 3 years ago

#14669 closed defect (bug) (duplicate)

get_categories returns only after page reload all cats

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

Description

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)

comment:1 christian_gnoth4 years ago

  • Severity changed from normal to major

comment:2 dd323 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.

comment:3 filosofo3 years ago

  • Milestone changed from Awaiting Review to Future Release

comment:4 follow-up: christian_gnoth3 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.

comment:5 in reply to: ↑ 4 scribu3 years ago

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

This is just another symptom of #14485

comment:6 SergeyBiryukov3 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.