Join WhatsApp ChannelJoin Now

Custom Post Type Form Send In WordPress

Hi Dev,

Today, i we will show you custom post_type form send in wordpress. This article will give you simple example of custom post_type form send in wordpress. you will custom post_type form send in wordpress. In this article, we will implement a custom post_type form send in wordpress.

So let’s follow few step to create example of custom post_type form send in wordpress.

Example

<?php

		 if(isset($_POST['submit'])){
            date_default_timezone_set("Asia/Calcutta"); 

            $title=$_POST['name']."_".date('YmdHis');
            $name=$_POST['name'];            
            $email=$_POST['email'];
            


            $content .= '<p> Name:- '.$name.'</p>';            
            $content .= '<p> Email Address:- '.$email.'</p>';
            
        
        // Create post object
        $post = array(
            'post_title'    => $title,
            'post_content'  => $content,
            'post_type'     =>'post',
            'post_status'   => 'publish',
            'post_author'   => 1
        );


        

$pid = wp_insert_post( $post, $wp_error='' );

if($pid!=0){

    if ($_FILES) {
        foreach ($_FILES as $file => $array) {
        $newupload = insert_attachment($file,$pid);
        // $newupload returns the attachment id of the file that
        // was just uploaded. Do whatever you want with that now.
        }
    }
          ////////////////////
            echo "<span class='message'>successfully send</span>";
        }	
        
    }
?>

<form id="myForm" action=""  method="post" enctype="multipart/form-data">
  
       <input type="text" placeholder="Name"  name="name">
       <input type="text" placeholder="Email"  name="email">


</form>

I hope it will assist you…

Recommended Posts