0

Here is the simple front end post submission form code

<?php $postTitle = $_POST['post_title'];
$post = $_POST['post'];
$submit = $_POST['submit'];

if(isset($submit)){

    global $user_ID;

    $new_post = array(
        'post_title' => $postTitle,
        'post_content' => $post,
        'post_status' => 'publish',
        'post_date' => date('Y-m-d H:i:s'),
        'post_author' => $user_ID,
        'post_type' => 'post',
        'post_category' => array(0)
    );

    wp_insert_post($new_post);

}

?>
<!DOCTYPE HTML SYSTEM>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled Document</title>
</head>

<body>
<div id="wrap">
<form action="" method="post">
<table border="1" width="200">
  <tr>
    <td><label for="post_title">Post Title</label></td>
    <td><input name="post_title" type="text" /></td>
  </tr>
  <tr>
    <td><label for="post">Post</label></td>
    <td><input name="post" type="text" /></td>
  </tr>
</table>

<input name="submit" type="submit" value="submit" />
</form>
</div>

</body>
</html>

Its working. But can anyone give me some sample code for "Add another image" type custom fields.

Update:

Hi i'm using magic fields plugin. I have a custom field called "products image". This is the custom field id "products_image'. That plugin uses meta table to store its custom fields values. I would like to have "Add another image" button in the form. So the users can upload additional product images

Thanks

12
  • No validation...?
    – kaiser
    Feb 15, 2012 at 20:36
  • No i'll deal with validation later. As of now i would like to know how to add duplicate type fields. Feb 15, 2012 at 20:41
  • Where are you adding the first image that you want to add ANOTHER image?
    – mor7ifer
    Feb 15, 2012 at 20:43
  • @m0r7if3r Hi i'm using magic fields plugin. I have a custom field called "products image". This is the custom field id "products_image'. That plugin uses meta table to store its custom fields values. I would like to have "Add another image" button in the form. So the users can upload additional product images. Feb 15, 2012 at 20:52
  • 1
    I don't see the code for that in your question...
    – mor7ifer
    Feb 15, 2012 at 21:16

1 Answer 1

2

Take a look at this answer and at to store the image as a custom field replace:

update_post_meta($new_post,'_thumbnail_id',$attach_id);

with what ever name you have for you custom field ex:

update_post_meta($new_post,'products_image',$attach_id);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.