Insert/Create Category if it doesn’t exist
-
My goal is just to use some type of default method for checking if category exist in WordPress, and if it doesn’t, add the category. Same with tags.
Here is a mess I made trying to make it happen:
<?php if ( is_term( ‘football’ , ‘category’ ) ){
}
else (
$new_cat = array(‘cat_name’ => ‘Football’, ‘category_description’ => ‘Football Blogs’, ‘category_nicename’ => ‘category-slug’, ‘category_parent’ => ‘sports’);
$my_cat_id = wp_insert_category($new_cat); )
I plan to add this as a plugin. Any thoughts or help would be great!
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Insert/Create Category if it doesn’t exist’ is closed to new replies.