Results 1 to 3 of 3

Thread: Strange behavior with wp_insert_category

  1. #1
    mwaterous's Avatar
    mwaterous is offline Hello World
    Join Date
    Apr 2010
    Location
    Nevad'r
    Posts
    4

    Default Strange behavior with wp_insert_category

    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.

  2. #2
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,801

    Default

    Quote Originally Posted by mwaterous View Post
    I apologize in advance for cross posting this from the WordPress.org forums to here
    It would be handy if you posted the URLs for both pages on both sites, that way we can make sure no one has already answered your question before attempting it ourselves.

  3. #3
    mwaterous's Avatar
    mwaterous is offline Hello World
    Join Date
    Apr 2010
    Location
    Nevad'r
    Posts
    4

    Default

    My apologies, I also forgot to add that if the solution is discovered here I'll post it over there as well.

    Here's the link: http://bit.ly/9GjQlf

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •