WordPress.org

Ready to get started?Download WordPress

Forums

wp_insert_is_killing_me() (1 post)

  1. Mark Waterous
    Member
    Posted 4 years ago #

    I can't figure out the behaviour that I'm seeing as a result of using wp_insert_category and wp_insert_term.

    If I use wp_insert_category with a defined slug, I'm having the parent categories slugs automatically appended to them. If I use wp_insert_term, I get the appropriate category slug, but it's not assigning it to the right parent (or any for that matter).

    I'm losing my mind.

    $cid = get_term_by( 'slug', $slug, 'category' )->term_id;
    
    if ( is_null( $cid ) )
    	$cid = wp_insert_category( array( 'cat_name' => $name, 'category_nicename' => $slug, 'category_parent' => $parent ) );
    //		$cid = wp_insert_term( $name, 'category', array( 'alias_of' => $name, 'description' => '', 'parent' => $parent, 'slug' => $slug ) );
    
    return $cid;

    The above is the meat of the function. All variables are set, I've double checked them all. $parent is explicitly typed as an integer.

    The categories being inserted have two ancestors and I thought maybe this was a default behavior for that level of nesting, so I tested it. I wrote a loop that nested categories one under another using the last as the parent, and they all inserted with their own unique slug.

    I don't want the parent categories to append their slug to my children. I won't have it in my household. So what should I try doing?

Topic Closed

This topic has been closed to new replies.

About this Topic