最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

front end - Create posts by any logged in users

programmeradmin0浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论