[wp-trac] [WordPress Trac] #17356: Bug wp_insert_category not updating options

WordPress Trac wp-trac at lists.automattic.com
Mon May 9 12:35:06 UTC 2011


#17356: Bug wp_insert_category not updating options
-------------------------------+------------------------
 Reporter:  Archaniel          |       Owner:
     Type:  defect (bug)       |      Status:  closed
 Priority:  normal             |   Milestone:
Component:  Taxonomy           |     Version:  3.1.2
 Severity:  normal             |  Resolution:  duplicate
 Keywords:  reporter-feedback  |
-------------------------------+------------------------
Changes (by Archaniel):

 * version:   => 3.1.2


Comment:

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

 $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 :(

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/17356#comment:3>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list