Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Importing Data from a Non-WordPress database, into WP

You should wirte a Function or Plugin inside WordPress to achive that.

First, you could insert the tables into your WordPress Database.

After that, make sure you make good use of the WordPress postsstructure. Set up a Loop through your existing Posts that you want to import.

At each Post create a WordPress Post using wp_insert_post(). This Function returns the ID of your new Post.

Every bit of Metadata that you want to add to your Post is added afterwards.
It would be like this:

foreach ( $existingposts as $existingpost ) {

    $newPostData['post_date'] = $existingpost['post_date'];
    // and so on, make sure to populate all the fields except the ID parameter, as this one is given by WordPress

    $newPostID = wp_insert_post( $newPostData );

    add_post_meta( $newPostID, '_firstPostMeta', $existingpost['firstPostMeta'] );
    // and so on, every Meta at a time

}

Be sure to test your function before looping it through all the posts at once. You may want to divide your stack of existing posts into groups of 20 or 50, depending what your server is capable to do, to avoid inconsitensies due to server timeout.

Related Posts:

  1. delete duplicate meta_value with same post_id
  2. what is the correct way to compare dates in a WP query_posts meta_query
  3. Advanced search form with filters for custom taxonomies and custom fields
  4. Custom field values deleted when trashing custom post type
  5. How to get all custom fields of any post type
  6. Admin Area Custom Type Search By Meta Fields Without Title & Content
  7. How do I Paginate Search Results for Custom Post Types?
  8. Custom Post Type with Input fields to seperate table on database.
  9. Right way of storing large number of custom post fields
  10. How Can I save multiple records in same meta key?
  11. Detect meta value changes when post is updated (post_updated)
  12. Search everything (posts, pages, tags, cpt, meta)
  13. Custom post type or just use custom fields
  14. How to get source of custom meta image?
  15. Displaying Meta Box Image
  16. Using posts and postmeta table to store custom Address Book Plugin data
  17. ACF Upload Image in repeater from front-end with custom form? – add_post_meta()
  18. Formatting custom meta box date from YYYY/MM/DD to a more readable alternative
  19. Create a random unique 6 digit number as custom field for custom post type
  20. how to interconnect custom post types?
  21. List all images from a single post meta value
  22. Populate Custom Fields in a Custom Post Type?
  23. WP All Import – Using Xpath to set a select value
  24. Sorting custom post type columns with external data and without meta values
  25. Meta Key Value in current-user-only loop
  26. How to check if user meta field is empty in conditional else statement
  27. How to implement a Google map store locator
  28. Posting to a Custom Post Type from front end – user generated content
  29. Update Post Meta for a logged in user
  30. A better way to add a meta box to custom post types
  31. Two Custom Post Types Many to Many Relationship
  32. get_post_meta not working on publishing
  33. Store CPT ‘Reviews’ average ratings to a WordPress DB table or to a DB custom table?
  34. How do I set all of a particular post meta to a value within the custom post type I’m in?
  35. Custom fields (wp_post_meta) vs Custom Table for large amount of data
  36. Custom fields for custom post type
  37. Check if post with same meta value exists
  38. Specifying meta field’s column type in Database using add_post_meta
  39. Submitting Custom Post Types with custom fields from Front-end form
  40. create custom meta box with default value
  41. delete_post_meta() for whole CPT / multiple posts?
  42. How to get specific post meta by title or id
  43. copy images from custom field to another custom field
  44. How to show custom field on specific custom post type posts only when filled
  45. Cannot obtain custom meta information
  46. How can I output WPAlchemy repeating fields meta values in my page template?
  47. How to call a post’s metadata in shortcode.php?
  48. Ideas to connect external database table to wordpress posts as custom field source
  49. Search CPT Title AND Meta
  50. updating one custom meta field only
  51. Add a class to post_class if more than one post shares same meta_value_num
  52. Add a meta field to the list of results for a custom post type
  53. Empty meta-box returns publishdate if no value is set?
  54. Say I have a tech blog, how best would I store technical specs for a phone, if i use custom post types
  55. Filter search posts by post meta?
  56. Custom fields for post or terms which don’t update on post update
  57. Having a repeating custom field in admin custom post type, what I’d go better with, for DB’s sake? ACF repeater or query a different post type?
  58. Custom Post Type meta data getting deleted on bulk editing taxonomies
  59. Unable to gather Image URL from Custom Post Type’s; Custom Meta Field
  60. How to keep custom post type related information
  61. when looping through custom post data not appearing
  62. custom post types, custom fields and normalization
  63. How can I add a meta[] to my custom post type and search by term with the Rest API?
  64. Show posts from WP Custom Post Type selected from a field in a metabox
  65. Creating an archive page or simple template to list all values of a custom field of specific post type listing
  66. Where is get_post_meta value located?
  67. Custom meta fields not showing up in WP_Response Object via custom endpoint
  68. How to Disable option of meta field if that option is selected for any other post in custom post type?
  69. How to replicate data storage and querying using WordPress. Custom posts/fields or Custom db tables?
  70. Confused about where to store my data
  71. Add more custom fields when creating a new custom post type
  72. Populate custom post type/custom fields from an external database
  73. How do I extract the contents of a CPT’s custom field for all posts?
  74. Automatically convert standard posts with custom fields to custom post types
  75. Delete custom post type metadata without deleting the post in admin area
  76. How can I get the $key / $value pairs of custom fields that were added via 3rd party plugins or themes?
  77. How to enable the user to add value through the admin panel?
  78. How to add post reference field to a plugin?
  79. Displaying database table in backend of wordpress
  80. Advanced search form with filters for custom taxonomies and custom fields
  81. Querying meta values within an array
  82. Display a list of posts whose meta field values are equal to the ID of the post being viewed?
  83. Check for custom field value in different post type than current one and do something
  84. Rewrite custom post type url’s adding meta box values
  85. Stopping WordPress from Auto Generating Image Files for Sizes
  86. Get Custom Field Values by Another Custom Field in WordPress
  87. Displaying custom posts only if custom meta box’s date is not expired
  88. Export entries and multiple custom field meta to .csv?
  89. Insert post metadata for all posts in CPT at once if metadata no existent
  90. Display custom post type from dynamic custom field
  91. Keep display metadata value on backend – Custom Metabox
  92. Dynamic dropdown select values depending on other custom field value
  93. Grouping metadatas into one
  94. How to Output which matched meta_keys were found from custom_type_posts?
  95. Custom Post type loop with ACF not displaying properly
  96. Custom post types category
  97. Order by post meta value gets random results
  98. Order Custom Posts by Several Fields
  99. Rich Custom Field for Custom Post type not saving
  100. 404 on Pages for Custom Post Type & Query_Posts
Categories custom-post-types Tags custom-field, custom-post-types, database, post-meta
Custom category URL rewriting
404 error using Meta for Permalink rewrite

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress