
Table of Contents
Importing CSV files into WordPress without using a plugin is a great way to streamline your content management process, particularly when handling large amounts of data. Whether you’re looking to import users, custom post types, or even WooCommerce products, doing it programmatically allows you to maintain full control over performance and security. In this guide, we’ll walk you through the steps for importing CSV files into WordPress without the use of a plugin, making it easier to import CSV to your WordPress database efficiently.
When and Why to Import CSVs Without Plugins
Importing data programmatically rather than using a plugin provides several advantages:
- Avoid Plugin Bloat: You don’t need to rely on third-party plugins that may slow down your site.
- Customizability: You can control which fields are imported and customize the process for your specific needs, such as importing custom post types or custom fields.
- Increased Security: By importing CSV data programmatically, you can sanitize and validate the data, ensuring that no malicious content gets injected into your WordPress site.
Updated Prerequisites (2025)
Before importing your CSV files into WordPress, ensure you meet the following prerequisites:
- WordPress Version: This method works for WordPress 6.6+ and newer versions, including 2024 and 2025 themes.
- PHP Version: PHP 8.1 or later is recommended for improved performance and compatibility.
- CSV File: Your CSV file should be UTF-8 encoded and properly formatted to ensure smooth data import.
- WP-CLI: Optional, but useful for automating CSV imports using command-line scripts.
Steps for Importing CSV to WordPress Without a Plugin
1. Prepare Your CSV File
Start by ensuring that your CSV file is clean and properly structured:
- The first row should contain column headers like post_title, post_content, post_status, etc.
- Ensure the file is UTF-8 encoded to avoid any encoding issues.
- Double-check that no special characters or extra spaces are present.
2. Create a Custom Script
To handle the CSV import process, you need to create a custom PHP script. This ensures you have complete control over the data and can sanitize inputs as necessary. Here’s how to begin:
// Get upload directory
$upload_dir = wp_upload_dir();
$csv_file = $upload_dir[‘basedir’] . ‘/posts.csv’;
This approach avoids using hardcoded file paths and makes the script compatible with WordPress 6.6+ and modern themes like 2024 and 2025.
3. Read the CSV Data Securely
Next, open the CSV file and start reading its contents. Ensure that all data is sanitized before being inserted into WordPress.
if (($handle = fopen($csv_file, "r")) !== FALSE) {
$header = fgetcsv($handle); // Read the header
while (($row = fgetcsv($handle)) !== FALSE) {
$data = array_combine($header, $row); // Combine headers with row data
// Sanitize and validate inputs
$title = sanitize_text_field($data['post_title']);
$content = wp_kses_post($data['post_content']);
try {
wp_insert_post([
'post_title' => $title,
'post_content' => $content,
'post_status' => 'publish',
'post_type' => 'post'
]);
} catch (Exception $e) {
error_log('CSV Import Error: ' . $e->getMessage());
}
}
fclose($handle);
}
This method uses input sanitization (like sanitize_text_field() and wp_kses_post()) to ensure that no harmful scripts are inserted into your WordPress posts. It’s important to handle these inputs carefully, especially if you’re dealing with user imports or WooCommerce products.

WP Ultimate CSV Importer Pro
Get Ultimate CSV/XML Importer to import data on WordPress faster, quicker and safer.
Importing Different Data Types Without a Plugin
Importing Custom Post Types without a Plugin
To import Custom Post Types (CPTs) into WordPress without using a plugin, you can use the native WordPress import/export functionality, or you can manually import them using SQL queries or through WP-CLI. Here’s a detailed guide on each method:
1. Import Custom Post Types using WordPress Export/Import Feature
WordPress has a built-in export and import feature that allows you to export content, including posts, pages, and custom post types. This is a relatively easy method, but it only works if your custom post types are set up correctly, and you want to import the content as posts.
Steps to Export Custom Post Types:
- On the WordPress Dashboard, navigate to Tools -> Export in your WordPress dashboard.
- Choose the Post Type to Export:
- You can choose the specific Custom Post Type (CPT) you want to export or Select All content.
- You can choose the specific Custom Post Type (CPT) you want to export or Select All content.
- Download the Export File:
- Click “Download Export File,” and it will generate an XML file (WXR format) containing the posts of the selected custom post type.
Steps to Import Custom Post Types:
- On the WordPress Dashboard, navigate to Tools -> Import in your WordPress dashboard.
- Install the WordPress Importer:
- If the importer is not already installed, click “Install Now” under the “WordPress” option.
- If the importer is not already installed, click “Install Now” under the “WordPress” option.
- Upload the Exported File:
- Choose the XML file you exported previously and upload it.
- Choose the XML file you exported previously and upload it.
- Assign Authors:
- During the import process, WordPress will ask if you want to assign authors or create new users.
- During the import process, WordPress will ask if you want to assign authors or create new users.
- Import Attachments:
- Make sure to check the option to download and import file attachments if needed.
While this method works for the basic transfer of posts and CPTs, it doesn’t handle custom fields, taxonomies, or post meta.
2. Import Custom Post Types Manually via SQL
If you have a more complex requirement, such as importing a large number of posts, custom fields, or taxonomies, you can import directly into the database using SQL. This method assumes you already have access to your WordPress database via phpMyAdmin or a similar tool.
- Prepare Your CSV File:
- Create a CSV file containing all the necessary information about your custom post types, such as post titles, content, custom fields, and taxonomies.
- The CSV should have columns like post_title, post_content, post_type, post_date, etc.
- Create a CSV file containing all the necessary information about your custom post types, such as post titles, content, custom fields, and taxonomies.
- Prepare Your SQL Import Script:
- If you’re manually inserting data into the database, you’ll need to write SQL queries that match the structure of WordPress’s wp_posts, wp_postmeta, and wp_term_relationships tables.
Here’s an example SQL query to import a basic CPT:
INSERT INTO wp_posts (post_title, post_content, post_type, post_date)
VALUES
(‘Post Title 1’, ‘Post Content 1’, ‘your_cpt’, NOW()),
(‘Post Title 2’, ‘Post Content 2’, ‘your_cpt’, NOW());
- Import Data into wp_postmeta for Custom Fields:
- If you have custom fields, you’ll need to insert them into the wp_postmeta table. For example:
INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
VALUES
(1, ‘your_custom_field_key’, ‘value_for_post_1’),
(2, ‘your_custom_field_key’, ‘value_for_post_2’);
- Import Data into wp_term_relationships for Taxonomies:
- If your CPT uses custom taxonomies (like categories or tags), you’ll need to insert them into the wp_term_relationships table.
- Execute the SQL Script:
- You can run these SQL queries using phpMyAdmin or directly through a MySQL command line interface to insert the data into your WordPress database.
Bonus: Use AI to Enhance Your Script
You can generate or optimize your import script using tools like ChatGPT:
“Write a WordPress-compatible PHP script that imports custom post types from a CSV file using sanitized inputs.”
This can save time and reduce errors during development.

WP Ultimate CSV Importer Pro
Get Ultimate CSV/XML Importer to import data on WordPress faster, quicker and safer.
Import Users Without a Plugin
To import users into WordPress without a plugin, you can follow the same general process using SQL or WP-CLI.
Import Users Using SQL:
You can directly insert user data into the WordPress wp_users and wp_usermeta tables. Here’s a basic SQL example:
Insert into wp_users:
INSERT INTO wp_users (user_login, user_pass, user_email, user_registered, display_name)
VALUES
(‘newuser1’, MD5(‘password1’), ‘[email protected]’, NOW(), ‘New User 1’),
(‘newuser2’, MD5(‘password2’), ‘[email protected]’, NOW(), ‘New User 2’);
Note: Use the MD5 function to encrypt passwords (WordPress internally uses a more secure method, but MD5 works for this purpose).
Insert User Meta Data:
If you have user metadata (such as roles, custom fields), insert it into the wp_usermeta table:
INSERT INTO wp_usermeta (user_id, meta_key, meta_value)
VALUES
(1, ‘wp_capabilities’, ‘a:1:{s:10:”subscriber”;b:1;}’),
(1, ‘wp_user_level’, ‘0’);
- The wp_capabilities meta field determines the user’s role (e.g., subscriber, administrator, etc.).
Import Users Using WP CLI:
Create Users with wp user create:
You can use WP CLI’s wp user create command to import users. For example:
wp user create newuser1 [email protected] –role=subscriber –user_pass=password1
wp user create newuser2 [email protected] –role=administrator –user_pass=password2
Batch User Import via Script:
If you have a CSV of users, you can create a bash script that reads the file and uses WP CLI commands:
#!/bin/bash
while IFS=, read -r username email password role
do
wp user create “$username” “$email” –role=”$role” –user_pass=”$password”
done < users.csv
Execute the Script
Once your script is ready, you can execute it in various ways:
- As a page template or theme function: You can place this script in your theme’s functions.php or create a custom page template.
- Via WP-CLI: Use WP-CLI for batch processing large CSV files to avoid memory or timeout errors.
For example, running a custom PHP script using WP-CLI could look like this:
wp eval-file import-posts.php

WP Ultimate CSV Importer Pro
Get Ultimate CSV/XML Importer to import data on WordPress faster, quicker and safer.
WP-CLI for Advanced Users (2025)
If you prefer working in the command line, WP-CLI offers powerful tools for CSV imports.
Here’s a basic WP-CLI user import command:
wp user import-csv users.csv
For custom post types or complex imports, you might write a script and execute it via WP-CLI:
wp eval-file import-posts.php
Using WP-CLI allows you to avoid timeouts and memory errors when importing large CSV files.
WP-CLI is a powerful command-line tool for managing WordPress sites, and it offers a method to import posts, custom post types, users, and other data via the command line. Here’s how you can use WP-CLI to import custom post types:
Step 1: Install WP CLI (If Not Installed)
You can install WP CLI by following the installation instructions on WP-CLI’s official site. If you’re using cPanel, Plesk, or another hosting environment, WP-CLI might already be installed.
Step 2: Prepare Your Data (CSV, JSON, etc.)
You can import your data using CSV or JSON formats. For this example, let’s assume you’re using a CSV file containing your CPT data.
Step 3: Import Custom Post Types via WP CLI
You can use the wp post create or wp post import commands in WP CLI. Here’s a detailed process:
Navigate to Your WordPress Directory:
Open your terminal and navigate to the root of your WordPress installation.
cd /path/to/your/wordpress
Import Using wp post create:
- If you have a simple CSV and want to create posts individually, you can loop through the CSV and use the wp post create command.
For example: wp post create –post_type=”your_cpt” –post_title=”Your Post Title” –post_content=”Content for the CPT” –post_status=”publish”
- To automate this, you can use a script that reads the CSV and executes this command for each row.
Example Script (Bash with CSV Import):
Assuming you have a CSV file with post titles and content, you can use a bash script to import posts:
#!/bin/bash
while IFS=, read -r post_title post_content
do
wp post create –post_type=”your_cpt” –post_title=”$post_title” –post_content=”$post_content” –post_status=”publish”
done < posts.csv
This script creates a custom post for each row as it reads from posts.csv.
Import Using JSON (Advanced):
If your data is in JSON format, you can use WP CLI’s wp post import functionality (though you’ll need to install the required package).
You can create a JSON file like this:
[
{
"post_title": "Post 1",
"post_content": "Content for Post 1",
"post_type": "your_cpt"
},
{
"post_title": "Post 2",
"post_content": "Content for Post 2",
"post_type": "your_cpt"
}
]
Then use the following command to import:
wp post import posts.json –post_type=”your_cpt”
Performance Tips for Handling Large CSV Files
If you’re dealing with a massive CSV file, you may encounter memory errors or slow performance. Here are a few tips to handle large datasets efficiently:
- Batch Processing: Process the CSV in smaller chunks to avoid hitting PHP’s memory limits.
- Increase Memory Limits: Add the following code to your wp-config.php file to increase the memory limit: define(‘WP_MEMORY_LIMIT’, ‘512M’);
- Use Transients: If you need to pause and resume the import process, consider saving the current state using transients or custom database checkpoints.
Security Best Practices
When working with CSV imports, security is paramount to prevent malicious data injection. Here’s how to ensure a secure import process:
- Sanitize Inputs: Always sanitize user inputs and data from external sources using functions like sanitize_text_field() and wp_kses_post().
- Validate CSV Files: Check for unexpected scripts or malicious code within your CSV files before processing them.
- Restrict Access: Limit access to the script only to authenticated users with admin privileges.
- Use Nonces: If you create a custom form for CSV uploads, include WordPress nonces to protect against cross-site request forgery (CSRF).
Eco-Friendly Tip
To reduce server load and minimize environmental impact, consider running your import scripts locally during development or using your staging environment rather than your live site.
Frequently Asked Qustions
1. What WordPress versions support these import methods?
This method works for WordPress 6.6+ and newer versions. Older versions may require adjustments.
2. How do I handle large CSV files without memory errors?
You can split large files into smaller chunks or use batch processing to import the data incrementally.
3. Can I import custom post types without a plugin?
Yes! Use wp_insert_post() with the ‘post_type’ => ‘your_custom_post_type’ argument.
4. How do I secure my custom import script?
Sanitize inputs, restrict script access to authenticated users, and use WordPress nonces to prevent cross-site request forgery.
5. What if my CSV has special characters or encoding issues?
Ensure the CSV is UTF-8 encoded. You can also use mb_convert_encoding() to handle non-standard characters.
6. Can I automate these imports without a plugin?
Yes, use WP-CLI or schedule the import using CRON jobs to automate the process.
7. How do I debug errors in my import script?
Enable WP_DEBUG or use error_log() to track issues with the import process.
8. What are the risks of running import scripts on a live site?
The main risks include potential performance issues, data corruption, and security vulnerabilities. Always test in a staging environment first.
9. Can I import WooCommerce products without a plugin?
Yes, you can import WooCommerce products using custom scripts, but you’ll need to handle custom product meta fields and taxonomy relationships.
10. How does this compare to using a plugin like WP Ultimate CSV Importer?
Using a plugin may be easier for non-developers, but writing custom code gives you more flexibility, control, and potentially better performance.

WP Ultimate CSV Importer Pro
Get Ultimate CSV/XML Importer to import data on WordPress faster, quicker and safer.