I want to allow logged-in any users to create posts. For this purpose I created a form
<form>
<div class="form-group">
<input type="text" class="form-control" id="post_title" placeholder="Title">
</div>
<div class="form-group">
<textarea class="form-control" id="post_content" rows="10" placeholder="Content should go here..."></textarea>
</div>
<button type="submit" class="btn btn-primary" >Submit your post</button>
</form>
I was following WP_INSERT_POST but I am confused about the hook and finally I hooked it in ADMIN_INIT (just from guesses) and here the code in functions.php
function test_insert_post_function() {
$postarr = array(
'post_title' => $_POST['post_title'],
'post_content' => $_POST['post_content'],
'post_status' => 'publish',
'post_author' => get_the_author_meta('ID'),
'post_category' => array(1)
);
wp_insert_post( $postarr );
}
add_action('admin_init', 'test_insert_post_function');
Now I am not finding a way to make a relation between the submit-button & this Function
Here is the theme files:
And here is the temporary live URL: /
I found few similar questions here but those were asked & answered 6/7 years ago.
So how can I achieve this goal?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745312504a4622064.html
评论列表(0条)