无法将数据插入到多个表的WordPress(Unable to insert data into m

2019-08-02 04:10发布

我创建WordPress的标签导入/导出插件。 但我有一个问题。

正如我们所知道的标签实际上是占据wp_terms在数据库中,以及wp_term_taxonomy

所以,我想出了一个计划,但它不工作。

请检查下面的代码,让我知道我怎么能解决这个问题。 因为我输入nameslug从Excel文件,并试图挽救wp_terms表以及试图挽救term_idwp_term_taxonomy

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][0], $data->sheets[0]['cells'][$i][1])); 

            // 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>";
}

请检查并让我知道。

文章来源: Unable to insert data into multiple wordpress tables