Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7505857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:03:38+00:00 2026-05-29T22:03:38+00:00

The following snippet adds WordPress categories programmatically. My question is how do you add

  • 0

The following snippet adds WordPress categories programmatically. My question is how do you add tags programmatically?

//Define the category
$my_cat = array('cat_name' => 'My Category', 'category_description' => 'A Cool Category', 'category_nicename' => 'category-slug', 'category_parent' => '');

// Create the category
$my_cat_id = wp_insert_category($my_cat);

In this question, I’m talking about adding the tags into database programmatically.

Say, I got 1000 tags to add to a fresh installation. And I don’t want to go through the regular admin panel to add tags one by one manually. I’m looking for a programmatic solution. The snippet I posted takes care of the add of cats… thanks to the specific wp function wp_insert_category…. there is no function called wp_insert_tag though…

However, looking at the codex, I see the wp_insert_term function which may very well be the one to do the job – it seems.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T22:03:39+00:00Added an answer on May 29, 2026 at 10:03 pm

    Use wp_insert_term() to add categories, tags and other taxonomies, because wp_insert_category() fires a PHP error “Undefined function”.

    <?php wp_insert_term( $term, $taxonomy, $args = array() ); ?> 
    

    $term is the term to add or update.

    Change the value of $taxonomy into post_tag if it’s a tag and category if it’s a category.

    In $args array, you can specify values of inserted term (tag, category etc.)

    Example:

    wp_insert_term(
      'Apple', // the term 
      'product', // the taxonomy
      array(
        'description'=> 'A yummy apple.',
        'slug' => 'apple',
        'parent'=> $parent_term['term_id']  // get numeric term id
      )
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following snippet of C# code: int i = 1; string result = String.Format({0},{1},{2},
The following snippet is supposed to take the value of PROJECT (defined in the
In the following snippet: public class a { public void otherMethod(){} public void doStuff(String
Take the following snippet: List<int> distances = new List<int>(); Was the redundancy intended by
In the following snippet, using XmlReader, when I encounter an element. I would like
I have the following snippet in one of my html pages : <div class=inputboximage>
I have the following snippet of code, changeTextArea is a TextArea object. changeTextArea.addKeyboardListener(new KeyboardListenerAdapter()
I have the following snippet where I would like to extract code between the
Consider the following snippet: using System; using System.Collections.Generic; using System.Linq; using System.Net; namespace ForumLogins
I have the following snippet of code that's generating the Use new keyword if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.