• 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)
  • 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.

    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?

    @n3v3rl0v3 you can add post meta by using
    <?php add_post_meta($post_id, $meta_key, $meta_value, $unique); ?>
    and
    click here 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.