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

  • SEARCH
  • Home
  • 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 8765465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:17:24+00:00 2026-06-13T16:17:24+00:00

Possible Duplicate: Unable to insert data into multiple wordpress tables According to the above

  • 0

Possible Duplicate:
Unable to insert data into multiple wordpress tables

enter image description here

According to the above diagram I have 2 tables and each table have 1 common column, but the issue is that I have to add the same values in both columns rows. Although wp_terms.term_id has auto increment in database. But I am not understanding how I copy and use wp_terms.term_id value in wp_term_taxonomy.term_id.

I had tried an sql query which i given below:

// create a tag
$query = "INSERT INTO $wpdb->terms (name, slug) VALUES (%s, %s)";
$wpdb->query($wpdb->prepare($query, $name, $slug));

// create the relationship 
$query = "INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy) VALUES (%d, %s)";  
$wpdb->query($wpdb->prepare($query, LAST_INSERT_ID, 'post_tag')); 

But after running this script when I check database through phpmyadmin, i notice that wp_terms table filled correctly but wp_term_taxonomy > term_id column is empty.

And my Actual codes are:

$file_name = $_FILES['tag_import']['name'];
$file_ext = strtolower(end(explode(".", $file_name)));
$file_size = $_FILES['tag_import']['size'];

if (( $file_ext == "xls" ) && ( $file_size < 500000 )) 
{       
    $data = new Spreadsheet_Excel_Reader();
    $data->setOutputEncoding('CP1251');
    $data->read($_FILES['tag_import']['tmp_name']);

    for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++)
    {
        for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++)
        {
            // add the new category 
            $query = "INSERT INTO $wpdb->terms (name, slug) VALUES (%s, %s)";
            $wpdb->query($wpdb->prepare($query, $data->sheets[0]['cells'][$i][1], $data->sheets[0]['cells'][$i][2])); 

            // create the relationship 
            $query = "INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy) VALUES (%d, %s)";  
            $wpdb->query($wpdb->prepare($query, LAST_INSERT_ID, 'post_tag'));           
        }
    }
    else  
    {
        echo "<div class='error'><p>Invalid file or file size too big.</p></div>";
    }
}

Please guide me how can I do that?

  • 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-06-13T16:17:26+00:00Added an answer on June 13, 2026 at 4:17 pm

    I dont do much wordpress but from the documentation it looks like the last id is only filled on wpdb when you use the insert() method as opposed to using query() like you are doing. And its not a global constant its a class variable.

    $wpdb->insert('terms', array(
      'name' =>  $data->sheets[0]['cells'][$i][1],
      'slug' => $data->sheets[0]['cells'][$i][2]
    ));
    
    $wpdb->insert('term_taxonomy', array(
      'term_id' => $wpdb->insert_id,
      'taxonomy' => 'post_tag'
    ));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Unable to send an email to multiple addresses/recipients using C# I have
Possible Duplicate: Cannot insert explicit value for identity column in table ‘table’ when IDENTITY_INSERT
Possible Duplicate: Android RuntimeException: Unable to instantiate the service I am downloading my data
Possible Duplicate: Unable to Populate TableView In PopOverController - Objective C I am using
Possible Duplicate: Unable to publish web service which is created in java using eclipse
Possible Duplicate: Unable to reverse a linked list I'm trying to reverse a linked
Possible Duplicate: Unable to process application info.plist validation at this time due to a
Possible Duplicate: How to power off an Android device? I have a requirement to
Possible Duplicate: Unable to get a list of installed Python modules How do I
Possible Duplicate: it's a google weather api?how to parse such kind of data using

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.