Make WordPress Core

Opened 15 years ago

Closed 14 years ago

#14471 closed defect (bug) (duplicate)

wp_create_category not working properly

Reported by: christian_gnoth's profile christian_gnoth Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Taxonomy Keywords: wp admin category display
Focuses: Cc:

Description

I am deleting categories and creating them through a theme script function.

I first delete all categories who are child_of a parent cat. After that I delete the parent cat and create the parent cat and all child cats.

In the wp admin backend under the category section I see all created categories, but the Tree structure is not displayed correctly. The created childs are not displayed as childs of the parent cat. there are threee levels - teh parent cat, one sub-cat of that and many child cats. the child cats are displayed as childs of the sub-cat, but the sub-cat is not displayed as child of the parent.

If I try to manually edit the sub-cat I get in the drop-down list for the parent selection the whole tree displayed. In this drop down list the tree structure is correct and the sub-cat is already displayed as child of the parent cat.

after that manual selection the tree structure is displayed correctly.

Attachments (2)

screenshot.gif (39.7 KB) - added by christian_gnoth 15 years ago.
screenshot of the wp backend category section
screen-1.png (111.3 KB) - added by christian_gnoth 14 years ago.

Download all attachments as: .zip

Change History (23)

#1 @christian_gnoth
15 years ago

  • Severity changed from normal to critical

I create a category with:

$biq_amazon_brands_cat = wp_create_category('Designer Shoe Brands', intval($biq_amazon_cat) );

the created categorie is not visible in the category section - the variable is filled with an int value as a var_dump is displaying.

#2 @christian_gnoth
15 years ago

wp version is 3.0.1

#3 @christian_gnoth
15 years ago

  • Severity changed from critical to blocker

as I saw now - the create category statements are done - I see the categories in the parent drop down list, but they are not visible in the Category view and to not in a wp_list_category statement.

@christian_gnoth
15 years ago

screenshot of the wp backend category section

#4 @christian_gnoth
15 years ago

  • Severity changed from blocker to major

found a work around

#6 @christian_gnoth
15 years ago

can anyone give a feedback about the status of this problem???

#7 @nacin
14 years ago

  • Keywords reporter-feedback added; wp_create_category child_of child category removed

Please try trunk. You likely have a closed circuit in your hierarchy.

#8 @nacin
14 years ago

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

#9 @christian_gnoth
14 years ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

I have at this moment no installation were I can try a development snapshot, so please keep it open until I have tested it.

#10 @scribu
14 years ago

  • Resolution set to invalid
  • Status changed from reopened to closed

How about we keep it closed and you can reopen it when you have steps to reproduce in trunk.

#11 @scribu
14 years ago

Also, you might want to google for how to install WordPress locally.

#12 @christian_gnoth
14 years ago

  • Resolution invalid deleted
  • Severity changed from major to minor
  • Status changed from closed to reopened

I opened it as a bug.

The categories are created with a parent ids, they are displayed in the select tag properly, but not in the box with checkboxes.

It is a bug, there is no question about it.

If you think it is solved in your development snapshot of wordpress, ok, I will test it if I have installed it.
At this moment I have two other projects were I am working and after taht I am testing it.

if you think you have solved it, you can close it, as with the next release it is solved.
If you want me to test if it is solved, keep it open.

#13 @mrmist
14 years ago

  • Keywords alot added; reporter-feedback removed

#14 @JohnONolan
14 years ago

  • Keywords drillbabydrill added
  • Resolution set to invalid
  • Status changed from reopened to closed

#15 @christian_gnoth
14 years ago

  • Keywords alot drillbabydrill removed
  • Resolution invalid deleted
  • Status changed from closed to reopened

same with the 3.1 alpah release. the screenshot I have added. here the php source code:

function  biq_update_amazon_brand_cats()
{
  global $wpdb;

  //  delete existing categories
  if ( $biq_amazon_cat = get_cat_ID( 'Amazon' ) )
  {
    $args = array(    
             'type'          => 'post',    
             'child_of'      => $biq_amazon_cat,
             'order_by'      => 'id',
             'order'         => 'desc',
             'hide_empty'    => 0
             );
    $biq_categories = get_categories( 'hide_empty=0' ); 
    $biq_blog_post_cat = get_cat_ID( 'Blog Post' );
    $biq_amazon_brands_cat = get_cat_ID( 'Designer Shoe Brands' );
    foreach( $biq_categories as $biq_category )
    {
      if ( ($biq_category->category_parent == $biq_amazon_cat) OR ($biq_category->category_parent == $biq_amazon_brands_cat) )
        wp_delete_category( $biq_category->cat_ID );
    }
  }

  //  check for categories and create categories in wp 
  if ( !($biq_amazon_cat = get_cat_ID( 'Amazon' )) )
    $biq_amazon_cat = wp_create_category( 'Amazon' );

  if ( !($biq_amazon_brands_cat = get_cat_ID( 'Designer Shoe Brands' )) )
    $biq_amazon_brands_cat = wp_create_category( 'Designer Shoe Brands', $biq_amazon_cat);

  //  get all brands from the amazon_attributes table
  $query = "select distinct brand from `amazon_attributes`;";
  $biq_amazon_brand_list = $wpdb->get_results($query);
  if ( $biq_amazon_brand_list )
    foreach ( $biq_amazon_brand_list as $biq_amazon_brand )
    {
      $biq_cat_id = wp_create_category( $biq_amazon_brand->brand, $biq_amazon_brands_cat );
    }

  return;
}

the cats are created and deleted, but not displayed. maybe the cache were the cats are stored is not correct?

#16 @christian_gnoth
14 years ago

  • Keywords wp admin category display added
  • Severity changed from minor to normal

if I put the following code just before the "return" of the function it is working:

			wp_cache_delete('all_ids', 'category');
			wp_cache_delete('get', 'category');
			delete_option("category_children");
			// Regenerate {$taxonomy}_children
			_get_term_hierarchy('category');

#17 @christian_gnoth
14 years ago

the Parent "select" tag is generated by

wp_dropdown_categories(array('hide_empty' => 0, 'hide_if_empty' => false, 'taxonomy' => $taxonomy, 'name' => 'parent', 'orderby' => 'name', 'hierarchical' => true, 'show_option_none' => ('None')));

and is working properly.

The category list table is generated by:

$wp_list_table->display_table();

I think it would be good, if the cache is cleared in the mothod display_table()

#18 @scribu
14 years ago

As the name implies, display_table() is for displaying the table, not for clearing caches.

I imagine the problem is that you're trying to clear the cache in the same page load. WordPress usually does a redirect after modifying something in the database.

#19 @christian_gnoth
14 years ago

that is not the problem here.
I am creating categories with wp_create_category.

after that they are not displayed properly in the wp backend under "Posts" -> "Categories".

So if I delete one cat - the delete_term functions performs a

clean_term_cache($term, $taxonomy);

Similiar the wp_create-cat should build the cache properly or the display_tables mthod.

as the wp-dropdown_categories works without problems, the problem is with the display_tables.

were is the best place to clean the cache, you have the knowledge about that. somewhere it has to be done, so that the categories are displayed properly!

#20 @garyc40
14 years ago

Related to #14485 (patched)

#21 @garyc40
14 years ago

  • Resolution set to duplicate
  • Status changed from reopened to closed

closed as duplicate of #14485

Note: See TracTickets for help on using tickets.