Hello all,
I apologize in advance for cross posting this from the WordPress.org forums to here, as I know most of you are over there as well. Even with the 'no replies' feature though, I'm sure you can understand how easy it is for a post to get buried under the weight of others.
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.
PHP Code:
$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've tried everything, I looked at the code for each function and I don't see where or why this is happening.