1
<form method="post">
<input type="text" name="title" /> //Title
<input type="text" name="desc" /> //Description
<input type="text" name="age" /> //Age autor
</form>

This code add title and description in new article. But how do I add custom date? ex. age input.

$title = $_POST['title'];
$desc = $_POST['desc'];

$date = array(
'post_title' => $title,
'post_content' => $desc,
'post_status' => 'publish'
);

wp_insert_post($date);

2 Answers 2

2

look into custom meta boxes. Here is an excellent article about it http://wp.smashingmagazine.com/2011/10/04/create-custom-post-meta-boxes-wordpress/

The initial function that allows you to save custom fields is add_post_meta(). Example:

add_post_meta( $post_id, $meta_key, $new_meta_value, true );

You could do the following if custom meta boxes is not what you are looking for:

$post_ID = wp_insert_post($date);
add_post_meta( $post_ID, 'custom_field', 'content for custom field', true );
Sign up to request clarification or add additional context in comments.

Comments

1

wp_insert_post will return an ID. You would then use that to add post meta.

https://codex.wordpress.org/Function_Reference/wp_insert_post https://codex.wordpress.org/Function_Reference/add_post_meta

E.g.

$id = wp_insert_post( $date );

$age = {GET AND SANITIZE YOUR AGE INPUT}

add_post_meta( $id, 'age', $age, true );

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.