admin管理员组文章数量:1326118
I have an excel column with around 1000 values, i need to import all these values into my wordpress database so i can create a small form with a text input and a submit button to let the users to add an input value and check if it exists in the imported values from the database.
What is the best way to do this, do i have to create a new table for this column or should i add it to an existing table?
I have an excel column with around 1000 values, i need to import all these values into my wordpress database so i can create a small form with a text input and a submit button to let the users to add an input value and check if it exists in the imported values from the database.
What is the best way to do this, do i have to create a new table for this column or should i add it to an existing table?
Share Improve this question asked Nov 28, 2017 at 7:09 TarekTarek 333 silver badges8 bronze badges1 Answer
Reset to default 2There is some way to import excel to WordPress database. but I have an easy solution to import this file.
- Go to convertcsv and convert your excel file to JSON.
- Create the below files and folders:
Folder: wp-content/plugins/import/
File: wp-content/plugins/import/import.json
File: wp-content/plugins/import/import.php
- Then save JSON file to import.json
- Put below code in import.php
.
/*
* Plugin Name: Import
* Plugin URI: https://veronalabs
* 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;
}
Go to Plugins and enable Import plugin. then run this request in your WordPress:
http://yoursite/wp-admin/?do=import
Don't forget, you should get valid data from your json. You can see this data through print_r
before each data.
本文标签: phpHow can I import an excel column into wordpress database
版权声明:本文标题:php - How can I import an excel column into wordpress database? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742192120a2430406.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论