Make WordPress Core

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#17356 closed defect (bug) (duplicate)

Bug wp_insert_category not updating options

Reported by: archaniel's profile Archaniel Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.1.2
Component: Taxonomy Keywords: reporter-feedback
Focuses: Cc:


wp_insert_category does not update options table with child information when inserting a child category

Found it out after digging deeply in and doing a diff on database dumps

was my first question

Please Fix

Change History (3)

#1 @westi
13 years ago

  • Keywords reporter-feedback added

It sounds like you are calling this from a standalone script.

Please provide an example PHP script which shows the issue you are seeing.

#2 @scribu
13 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

This is a known issue: #14485

#3 @Archaniel
13 years ago

  • Version set to 3.1.2

Excerpt from code (which is in a class function):

$dbimport is a class containing two arrays - $categories and $subcategories

    $woman_top_categories = array(
    // top-level categories
      array('cat_name'=>'Krása a Móda', 'cat_description'=>'', 'category_nicename'=>'krasa_a_moda', 'category_parent'=>0),
      array('cat_name'=>'Láska a Sex', 'cat_description'=>'', 'category_nicename'=>'laska_a_sex', 'category_parent'=>0),
      array('cat_name'=>'Deti', 'cat_description'=>'', 'category_nicename'=>'deti', 'category_parent'=>0),
      array('cat_name'=>'Zdravie', 'cat_description'=>'', 'category_nicename'=>'zdravie', 'category_parent'=>0),
      array('cat_name'=>'Lifestyle', 'cat_description'=>'', 'category_nicename'=>'lifestyle', 'category_parent'=>0),
      array('cat_name'=>'Poradňa', 'cat_description'=>'', 'category_nicename'=>'poradna', 'category_parent'=>0),
      array('cat_name'=>'Rady a nápady', 'cat_description'=>'', 'category_nicename'=>'rady_a_napady', 'category_parent'=>0),
      array('cat_name'=>'Archív', 'cat_description'=>'', 'category_nicename'=>'archiv', 'category_parent'=>0),

    foreach ($woman_top_categories as $category) {
       $this->dbimport->categories[$category['category_nicename']] = wp_insert_category( $category, false);
    // second level categories
    $subcategories = array(
      array('cat_name'=>'Pleť', 'cat_description'=>'', 'category_nicename'=>'plet', 'category_parent'=> $this->dbimport->categories["krasa_a_moda"]),
      array('cat_name'=>'Telo', 'cat_description'=>'', 'category_nicename'=>'telo', 'category_parent'=> $this->dbimport->categories["krasa_a_moda"]),
      array('cat_name'=>'Vlasy', 'cat_description'=>'', 'category_nicename'=>'vlasy', 'category_parent'=> $this->dbimport->categories["krasa_a_moda"]),
      array('cat_name'=>'Vône', 'cat_description'=>'', 'category_nicename'=>'vone', 'category_parent'=> $this->dbimport->categories["krasa_a_moda"]),
      array('cat_name'=>'Moda a Trendy', 'cat_description'=>'', 'category_nicename'=>'moda_a_trendy', 'category_parent'=> $this->dbimport->categories["krasa_a_moda"]),
    foreach ($subcategories as $category) {
       $this->dbimport->subcategories[$this->dbimport->categories["krasa_a_moda"]][$category['category_nicename']] = wp_insert_category( $category, false);

My current working workaround solution is :

  function updatechildopt(){
    $to_serialize = array();
      foreach ($this->dbimport->categories as $key=>$id) {
        if (is_array($this->dbimport->subcategories[$id]))
          foreach ($this->dbimport->subcategories[$id] as $subcatid) {
            $to_serialize[$id][] = $subcatid;
    global $wpdb;  
    $wpdb->query("UPDATE $wpdb->options SET option_value = '".serialize($to_serialize)."' WHERE option_name='category_children'");

my suggestion would be to create a small function within the taxonomy class that would be called from within wp_insert_category function, which would crawl through existing categories and automatically update the option table

I can code it later when I'm done with the project I'm currently working on, but honestly I don't feel myself to contribute to such a gigantic project like wordpress is :(

Note: See TracTickets for help on using tickets.