• I’m trying this with no luck…

    //insert the top-menu category
    if(is_term('top-media','category'))
    {
    echo "top-media category already exists";
    }
    else
    {
    	wp_create_category('top-menu');
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Try it this way

    $cat_id = wp_create_category('top-menu');
    if(!$cat_id) {
       echo "top-media category already exists";
    }

    $cat_id will have the id # of the newly created category. If WP can’t enter it (already exists) then $cat_id will be 0 which triggers the echo statement. should work

    Thread Starter vestaviascott

    (@vestaviascott)

    Sweet, thanks stvwlf

    Only problem I have is that I’m trying to do this update from my theme’s functions file via a hyperlink to a file I’ve created that contains the function. However, the function is undefined in my file since I don’t know which files to include that define the function. Perhaps there is another way to do it.

    I just want to provide a link in my custom theme’s function file that says “click here to create the category” and this would call a function that would execute the wp_create_category function.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How can I insert a category with script? If it does not already exist…’ is closed to new replies.