Title: programmatically add post &amp; attachment (about 7000 posts)
Last modified: August 19, 2016

---

# programmatically add post & attachment (about 7000 posts)

 *  [Vahid Nameni](https://wordpress.org/support/users/vahid216/)
 * (@vahid216)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/programmatically-add-post-attachment-about-7000-posts/)
 * Hello
    I was found the way how to add post programmatically but i cant found 
   it for adding attachment . I want to add about 7000 post with attachments in 
   fast way. And now how can do this?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Xephan](https://wordpress.org/support/users/xephan/)
 * (@xephan)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/programmatically-add-post-attachment-about-7000-posts/#post-1672614)
 * First you add the posts, then you add the attachments via the postmeta table.
   Each attachment appears to need two entries in postmeta, one for _wp_attached_file
   and one for its meta data _wp_attachment_metadata.
 *  [n3v3rl0v3](https://wordpress.org/support/users/n3v3rl0v3/)
 * (@n3v3rl0v3)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/programmatically-add-post-attachment-about-7000-posts/#post-1672705)
 * i too m stuck in like same thing…..
    I am really confused and messed up now a
   days in solving this up. I am getting post_title, post_content and other things
   in $_REQUEST… as well as an image file. I want to save all that as a post in 
   wordpress database. Can u help me up? here is what m getting on my page……. <?
   php require_once(“wp-config.php”); $user_ID; //getting it from my function $post_title
   = $_REQUEST[‘post_title’]; $post_content = $_REQUEST[‘post_content’]; $post_cat_id
   = $_REQUEST[‘post_cat_id’]; //category ID of the post $filename = $_FILES[‘image’][‘
   name’];
 * //I got this all in a array
 * $postarr = array(
    ‘post_status’ => ‘publish’, ‘post_type’ => ‘post’, ‘post_title’
   => $post_title, ‘post_content’ => $post_content, ‘post_author’ => $user_ID, ‘
   post_category’ => array($category) ); $post_id = wp_insert_post($postarr);
 * ?>
 * I dont know what to do next :(. This will get all the things in database as post.
   but what about attachment and its post meta .??? can anybody help me up?
 *  [ajithperuva](https://wordpress.org/support/users/ajithperuva/)
 * (@ajithperuva)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/programmatically-add-post-attachment-about-7000-posts/#post-1672742)
 * [@n3v3rl0v3](https://wordpress.org/support/users/n3v3rl0v3/) you can add post
   meta by using
    `<?php add_post_meta($post_id, $meta_key, $meta_value, $unique);?
   >` and [ click here](http://codex.wordpress.org/Function_Reference/add_post_meta)
   for more details. Good Luck 🙂

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘programmatically add post & attachment (about 7000 posts)’ is closed 
to new replies.

## Tags

 * [programmatically](https://wordpress.org/support/topic-tag/programmatically/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 3 replies
 * 4 participants
 * Last reply from: [ajithperuva](https://wordpress.org/support/users/ajithperuva/)
 * Last activity: [15 years, 6 months ago](https://wordpress.org/support/topic/programmatically-add-post-attachment-about-7000-posts/#post-1672742)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
