$id = wp_create_category('My category name');
By above function category created & categary id is returned.
If the category already exists, it is not duplicated. The ID of the original existing category is returned without error.
You can use $id
as category id.
Reference
http://codex.wordpress.org/Function_Reference/wp_create_category
Related Posts:
- How To Find Out WordPress Category Table in MYSQL?
- Add custom field to Category
- Get current category details the user is currently on in category.php
- Does the ‘cat’ argument in query_posts fetch posts from subcategories as well as the given ID?
- Get Default Post Category From Settings
- Are Categories, Tags and Custom Taxonomies any different in regards to SEO?
- Display list of Sub-Categories and the posts they contain, within one main Category
- Create subdomains for tags and categories
- Categories – create a new separate set right after the default?
- How to get this only in small letters (lowercase)? [closed]
- How to totally get rid of Category in my blog?
- Is there a function to cause empty categories not to show in menus?
- Add specific word before the category page title
- has_category() for parent category
- Getting the sub category
- How to have Multiple Archives Widgets, one archive widget per category (in a different page)?
- exclude category from WordPress Form function
- Render Selected Categories in Admin Edit Post Screen differently
- When to use ‘get_category_by_path’ vs. ‘get_term_by’ to get category object from `get_query_var( ‘category_name’ )`?
- How can I convert some categories to a custom taxonomy?
- Previous/next link to post in category, NOT tag?
- Any way to assign Post Categories and Tags to Links?
- One WP install, I need to map a custom domain name to each category
- Show thumbnail for category?
- get_the_category_list() does not give me all my categories
- How to add custom script to the particular Product Category page
- How to disable category without deleting?
- get_cat_ID() not wokring
- Get all sub-categories of a parent category
- How to create a page that shows posts from multiple categories
- How to get category name from URL and pass to a template
- Displaying multiple loops based off of category
- Display Categories, Sub-categories, and Sub-sub-categories on separate pages
- WooCommerce IF statements not working
- Category pie diagram meta box in post editing page
- I Cannot Create New Category
- Hide woocommerce category name from specific pages
- There any way to get de percentage of number of post by user and category?
- How to display categories which contains particular tag?
- I cannot add more Categories to my menu
- category permalinks
- Filtering *out* a taxonomy from the admin post list
- Displaying Child Categories in carousel
- Exclude current post from loop
- Removing Uncategorized on post save if other category present?
- Is there an easy way to get a list of Category IDs?
- Hidde certain category from post meta
- How to customize my category pages
- How to add a post without assigning to a category?
- Remove “Browsed by Category” from Category Page
- WordPress Categories in data-groups
- Not showing list if there aren’t any categories to display
- How to list all categories and their IDs using SQL query?
- How to display a value inside a post with a specified category from a category custom field? [closed]
- How to order get_categories() in the same order as the menu?
- Apply WordPress function on specific woocommerce product categories only
- display specific category on page
- Show different menu on each woocommerce category page
- How to let the user create a selection of categories via the backend
- Have posts that belong to multiple categories, exclude some categories from homepage
- Display subcategories selectbox on each category page
- Media (images, videos, etc.) not showing on Category page
- Get posts in a subcategory of a chosen parent
- How can I only display links from a child category
- Problem with Custom Post Type Categories
- Display post thumbnail for specific category outside the loop
- PHP dynamical conditional post display
- wp_dropdown_categories initial value
- Category Template – Show Last Entry as Featured
- can I ‘combine’ categories as a menu item?
- Displaying categories in different template problem
- List taxonomy terms assigned to a post in hierarchical view
- Limit categories to hierarchal depth of 2
- Count how many posts have a specified tag AND category
- Show the parent taxonomy by creating shortcode in woocommerce?
- Post List by category and under custom taxonomy
- Get_term_meta() does not work with pre_get_posts()
- Unable to add multiple categories to a post in WordPress
- How to display custom fields as table in Woocommerce
- make color of headline depend on category?
- How can I exclude a particular category from my WordPress Page 1 and Page 2?
- Balance Tags to the_content Words Length
- How to create template for children category?
- Categories and Tags Conflict after Woocommerce Installation
- how to display categories for a specific post?
- the_content() not showing full posts in category template
- Show parent category if there is no subcategory
- Add category links?
- show posts found in multiple categories via category_name query string?
- Removing categories, Comments etc from posts?
- Add html word before category
- Display last postings of 5 categories on homepage
- Problem importing categories and sub-categories
- Category that can hold only specific number of post
- How to add the sidebar in all category page
- Having Trouble With get_category_by_slug In a Custom Function
- how to ask if in two categorys inside if
- How to list out post category name and description in page
- Print child category slug nicename
- How to remove the category from the url only for a specific category of articles on wordpress