Categories

Monday, December 23, 2024
#919814419350 therichposts@gmail.com
Wordpress Cheat Codes

WordPress Cheat Code to add Post from Frontend

How to add custom meta title and meta description in Wordpress?

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.

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 19, MedusaJs, Next.js, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.