Skip to main content
Markup change
Source Link
fuxia
  • 107.1k
  • 38
  • 255
  • 459

`/*.

  • 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;
    

    }

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

`/*

  • 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;
    

    }

.

/*
* 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;
}
  1. Then save JSON file to import.json

  2. Put below code in import.php

    ' . print_r( $data, 1 ) Then save JSON file to import. ''; // 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; } json
  3. Go to Plugins and enable Import plugin. then run this request in your WordPress:

    http://yoursite.com/wp-admin/?do=import

    Put below code in import.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;
    

    }

  1. Go to Plugins and enable Import plugin. then run this request in your WordPress:

    http://yoursite.com/wp-admin/?do=import

Don't forgotforget, Youyou should get valid data from your json. You can see this data through print_r beforbefore each data.

  1. Then save JSON file to import.json

  2. Put below code in import.php

    ' . print_r( $data, 1 ) . ''; // 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; }
  3. Go to Plugins and enable Import plugin. then run this request in your WordPress:

    http://yoursite.com/wp-admin/?do=import

Don't forgot, You should get valid data from your json. You can see this data through print_r befor each data.

  1. Then save JSON file to import.json
  2. Put below code in import.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;
    

    }

  1. Go to Plugins and enable Import plugin. then run this request in your WordPress:

    http://yoursite.com/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.

Source Link

There is some way to import excel to WordPress database. but I have an easy solution to import this file.

  1. Go to convertcsv.com and convert your excel file to JSON.
  2. 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

  1. Then save JSON file to import.json

  2. Put below code in import.php

    ' . print_r( $data, 1 ) . ''; // 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; }
  3. Go to Plugins and enable Import plugin. then run this request in your WordPress:

    http://yoursite.com/wp-admin/?do=import

Don't forgot, You should get valid data from your json. You can see this data through print_r befor each data.