我有一个excel列,大约有1000个值,我需要将所有这些值导入wordpress数据库,这样我就可以创建一个带有文本输入和提交按钮的小表单,让用户添加输入值,并检查从数据库导入的值中是否存在输入值。
最好的方法是什么?我必须为此列创建一个新表还是应该将其添加到现有表中?
我有一个excel列,大约有1000个值,我需要将所有这些值导入wordpress数据库,这样我就可以创建一个带有文本输入和提交按钮的小表单,让用户添加输入值,并检查从数据库导入的值中是否存在输入值。
最好的方法是什么?我必须为此列创建一个新表还是应该将其添加到现有表中?
有一种方法可以将excel导入WordPress数据库。但我有一个简单的解决方案来导入此文件。
转到convertcsv.com 并将excel文件转换为JSON
wp-content/plugins/import/
File: wp-content/plugins/import/import.json
File: wp-content/plugins/import/import.php
然后保存JSON文件以导入。json在导入中放入下面的代码。php。
/*
* Plugin Name: Import
* Plugin URI: https://veronalabs.com
* Description: Import excel data to WordPress
* Author: Mostafa Soufi
* Version: 1.0
* Author URI: https://mostafa-soufi.ir
*/
if ( isset( $_GET[\'do\'] ) and $_GET[\'do\'] == \'import\' ) {
$json = file_get_contents( dirname( __FILE__ ) . \'/import.json\' );
if ( $json ) {
$data = json_decode( $json, true );
// Print your data
echo \'<pre>\' . print_r( $data, 1 ) . \'</pre>\';
// Each data
foreach ( $data as $item ) {
// Create post object
$args = array(
\'post_title\' => $item[\'title\'], // your column
\'post_content\' => $item[\'content\'], // your column
\'post_status\' => \'publish\',
\'post_type\' => \'post\',
\'post_author\' => 1
);
// Insert the post into the database
//$post_id = wp_insert_post( $args );
}
}
exit;
}
转到插件并启用导入插件。然后在WordPress中运行此请求:print_r 在每个数据之前。主题检查错误→REQUIRED: get_bloginfo(\'template_url\') was found in the file search.php. Use get_template_directory_uri() instead. Line 21: <img src=\'<?php echo get_bloginfo(\'template_url\') ?>/img/no_results_found.png\'/> 我采取了行动并进行了更改,但该图