Wordpress Cheat Codes

WordPress Cheat Code to add Post from Frontend

Views

Hello to all, welcome to therichpost.com. In this post, I will tell you, WordPress Cheat Code to add Post from Frontend.

Today, I am going to start new topic named WordPress Cheat Code
and in this topic, I will share all WordPress Cheat Code, which will help others to make wordpress code easy.
Today, I will write first post for this topic name WordPress Cheat Code to add Post from Frontend.

WordPress plays very important role in website world and I personally like WordPress very much. There are many WordPress developers in the world and I am one of the best WordPress developer(hahaha).

WordPress developers, today I am going to make your life easy with my today post.

In this post, I am just adding the title from frontend post form and In future posts, I will add post featured image and other things.

Here is the code for WordPress Cheat Code to add Post from Frontend and you can add this into any your wordpress theme’s template file.

<?php
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) &&  $_POST['action'] == "new_post") {
$new_post = array(
        'post_title'    =>  $_POST['title'],
        'post_status'   => 'publish', // Choose: publish, preview, future, draft, etc.
        'post_type'     => 'post' //'post',page' or use a custom post type if you want to
);
wp_insert_post($new_post);
}
?>
  <div class="row">
     <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
        <div class="card">
           <div class="card-header">
              <h2 class="card-title">Add POST</h2>
                </div>
                <div class="card-body">
                   <div class="row">
                       <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
                           <form id="new_post" name="new_post" method="post" action="">
                              <div class="form-group">
                                    <label>POST Title</label>
                                    <input type='text' class="form-control" required="" name="title" />
                                </div>
                                <div class="row">
                                    <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
                                        <div class="form-group">
                                            <input type="submit" value="Save" class="btn btn-custom login-btn pull-right"/>
                                        </div>
                                    </div>
                                </div>
                                <input type="hidden" name="action" value="new_post" />
                <?php wp_nonce_field( 'new-post' ); ?>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

 

This is it and if you have any query related to this post then please do comment below.

jASSA jATT,

Thank you.

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

Leave a Reply

Positive SSL