Skip to main content
minor
Source Link

Have a front-end form to create a post, Was only able to add text data to the new post (title, content, text-typed custom fields). I want to add a featured image to the new posts too.

It's a WordPress site and I use Avada theme. The custom post type is the Avada's default Portfolio post. But generalised answers would be very helpful too (please give some explanation on your code).

Please add some code to my PHP code and the form so that it can save a featured image too.

So, Here's my php code in fuctions.php in my child-theme:

    if(isset($_POST['title'])){

    $custom_field_address1 = $_POST['address1'];

    $my_post = array(

    'post_title' => $_POST['title'],
    'post_content' => $_POST['description'],
        
    'post_status' => 'publish', 
    'post_type' => 'companies''your_post_type_name',
    'meta_input' => array(
        'address1' => $custom_field_address1,
        )
    );
    
    $post_id = wp_insert_post($my_post);

    add_post_meta( $post_id, 'address1', $custom_field_address1, false );
    echo 'New Post Saved !';
    
    die;
    }

My front-end form:

<form method="post">
<div class="form-group">
      <label for="title">Post Title:</label>
      <input type="text" class="form-control" id="title" name="title">
</div>
    
    
<div class="form-group">
      <label for="pwd">Post Description :</label>
      <textarea class="form-control"  name="description"></textarea>
</div>
      
<div class="form-group">
      <label for="address1">Address :</label>
      <input type="text" name="address1" id="address1">
</div>

<BR>
<button type="submit" class="btn btn-default">Submit<type="submit">Submit</button>
</form>

Have a front-end form to create a post, Was only able to add text data to the new post (title, content, text-typed custom fields). I want to add a featured image to the new posts too.

It's a WordPress site and I use Avada theme. The custom post type is the Avada's default Portfolio post. But generalised answers would be very helpful too (please give some explanation on your code).

Please add some code to my PHP code and the form so that it can save a featured image too.

So, Here's my php code in fuctions.php in my child-theme:

    if(isset($_POST['title'])){

    $custom_field_address1 = $_POST['address1'];

    $my_post = array(

    'post_title' => $_POST['title'],
    'post_content' => $_POST['description'],
        
    'post_status' => 'publish', 
    'post_type' => 'companies',
    'meta_input' => array(
        'address1' => $custom_field_address1,
        )
    );
    
    $post_id = wp_insert_post($my_post);

    add_post_meta( $post_id, 'address1', $custom_field_address1, false );
    echo 'New Post Saved !';
    
    die;
    }

My front-end form:

<form method="post">
<div class="form-group">
      <label for="title">Post Title:</label>
      <input type="text" class="form-control" id="title" name="title">
</div>
    
    
<div class="form-group">
      <label for="pwd">Post Description :</label>
      <textarea class="form-control"  name="description"></textarea>
</div>
      
<div class="form-group">
      <label for="address1">Address :</label>
      <input type="text" name="address1" id="address1">
</div>

<BR>
<button type="submit" class="btn btn-default">Submit</button>
</form>

Have a front-end form to create a post, Was only able to add text data to the new post (title, content, text-typed custom fields). I want to add a featured image to the new posts too.

It's a WordPress site and I use Avada theme. The custom post type is the Avada's default Portfolio post. But generalised answers would be very helpful too (please give some explanation on your code).

Please add some code to my PHP code and the form so that it can save a featured image too.

So, Here's my php code in fuctions.php in my child-theme:

    if(isset($_POST['title'])){

    $custom_field_address1 = $_POST['address1'];

    $my_post = array(

    'post_title' => $_POST['title'],
    'post_content' => $_POST['description'],
        
    'post_status' => 'publish', 
    'post_type' => 'your_post_type_name',
    'meta_input' => array(
        'address1' => $custom_field_address1,
        )
    );
    
    $post_id = wp_insert_post($my_post);

    add_post_meta( $post_id, 'address1', $custom_field_address1, false );
    echo 'New Post Saved !';
    
    die;
    }

My front-end form:

<form method="post">
<div class="form-group">
      <label for="title">Post Title:</label>
      <input type="text" class="form-control" id="title" name="title">
</div>
    
    
<div class="form-group">
      <label for="pwd">Post Description :</label>
      <textarea class="form-control"  name="description"></textarea>
</div>
      
<div class="form-group">
      <label for="address1">Address :</label>
      <input type="text" name="address1" id="address1">
</div>

<BR>
<button type="submit">Submit</button>
</form>
deleted 520 characters in body
Source Link

Have a front-end form to create a post, Was only able to add text data to the new post (title, content, text-typed custom fields). I want to add a featured image to the new posts too.

It's a WordPress site and I use Avada theme. The custom post type is the Avada's default Portfolio post. So, I want the code to work on that post type.But generalised answers would be very helpful too (Couldn't use plugins like Post My CF7 Form. They didn't workplease give some explanation on my website. Need to writeyour code.).

Please add some code to my PHP code and the form so that it can save a featured image too.

So, Here's my php code in fuctions.php in my child-theme:

///////////////////////////////////////
///How to submit custom post type in wordpress from the Front-End

if(isset($_POST['title'])){
 

//echo $_POST['title']; // print title variable value

// create$custom_field_address1 post= object$_POST['address1'];

$custom_field_add1 = $_POST['add1'];
$custom_field_phone = $_POST['phone'];


$my_post = array(

    'post_title' => $_POST['title'],
    'post_content' => $_POST['description'],
        
    'post_status' => 'publish', 
    'post_type' => 'companies',
    'meta_input' => array(
    'add1'    'address1' => $custom_field_add1$custom_field_address1,
    'phone' => $custom_field_phone,  )
    )
);

 
// i use wordpres predefine function/
    $post_id = wp_insert_post($my_post);
///

add_post_meta( $post_id, 'add1', $custom_field_add1, false );
add_post_meta( $post_id, 'phone''address1', $custom_field_phone$custom_field_address1, false );
    echo 'New Post Saved !';
 
die; // stop script after 
 form submit  die;
    }

My CF7front-end form:

<form method="post">
<div class="form-group">
      <label for="title">Post Title:</label>
      <input type="text" class="form-control" id="title" name="title">
    </div>
    
    
    <div class="form-group">
      <label for="pwd">Descriptionfor="pwd">Post (PostDescription content):</label>
      <textarea class="form-control"  name="description"></textarea>
    </div>

 
       
<div class="form-group">
      <label for="add1">Addressfor="address1">Address :</label>
      <input type="text" name="add1"name="address1" id="add1">id="address1">
    </div>
    
      <div class="form-group"><BR>
    <button type="submit" <labelclass="btn for="phone">Phone:<btn-default">Submit</label>
      <input type="number" name="phone" id="phone">button>
    </div>

    <BR>
[submit]form>

Have a front-end form to create a post, Was only able to add text data to the new post (title, content, text-typed custom fields). I want to add a featured image to the new posts too.

It's a WordPress site and I use Avada theme. The custom post type is the Avada's default Portfolio post. So, I want the code to work on that post type. (Couldn't use plugins like Post My CF7 Form. They didn't work on my website. Need to write code.)

Please add some code to my PHP code and the form so that it can save a featured image too.

So, Here's my php code in fuctions.php in my child-theme:

///////////////////////////////////////
///How to submit custom post type in wordpress from the Front-End

if(isset($_POST['title'])){
 

//echo $_POST['title']; // print title variable value

// create post object

$custom_field_add1 = $_POST['add1'];
$custom_field_phone = $_POST['phone'];


$my_post = array(

'post_title' => $_POST['title'],
'post_content' => $_POST['description'],
    
'post_status' => 'publish', 
'post_type' => 'companies',
'meta_input' => array(
    'add1' => $custom_field_add1,
    'phone' => $custom_field_phone,
    )
);

 
// i use wordpres predefine function/
$post_id = wp_insert_post($my_post);
///

add_post_meta( $post_id, 'add1', $custom_field_add1, false );
add_post_meta( $post_id, 'phone', $custom_field_phone, false );
echo 'New Post Saved !';
 
die; // stop script after form submit
}

My CF7 form:

<div class="form-group">
      <label for="title">Post Title:</label>
      <input type="text" class="form-control" id="title" name="title">
    </div>
    
    
    <div class="form-group">
      <label for="pwd">Description (Post content):</label>
      <textarea class="form-control"  name="description"></textarea>
    </div>

 
      <div class="form-group">
      <label for="add1">Address:</label>
      <input type="text" name="add1" id="add1">
    </div>
    
      <div class="form-group">
      <label for="phone">Phone:</label>
      <input type="number" name="phone" id="phone">
    </div>

    <BR>
[submit]

Have a front-end form to create a post, Was only able to add text data to the new post (title, content, text-typed custom fields). I want to add a featured image to the new posts too.

It's a WordPress site and I use Avada theme. The custom post type is the Avada's default Portfolio post. But generalised answers would be very helpful too (please give some explanation on your code).

Please add some code to my PHP code and the form so that it can save a featured image too.

So, Here's my php code in fuctions.php in my child-theme:

    if(isset($_POST['title'])){

    $custom_field_address1 = $_POST['address1'];

    $my_post = array(

    'post_title' => $_POST['title'],
    'post_content' => $_POST['description'],
        
    'post_status' => 'publish', 
    'post_type' => 'companies',
    'meta_input' => array(
        'address1' => $custom_field_address1,
        )
    );
    
    $post_id = wp_insert_post($my_post);

    add_post_meta( $post_id, 'address1', $custom_field_address1, false );
    echo 'New Post Saved !';
     
    die;
    }

My front-end form:

<form method="post">
<div class="form-group">
      <label for="title">Post Title:</label>
      <input type="text" class="form-control" id="title" name="title">
</div>
    
    
<div class="form-group">
      <label for="pwd">Post Description :</label>
      <textarea class="form-control"  name="description"></textarea>
</div>
       
<div class="form-group">
      <label for="address1">Address :</label>
      <input type="text" name="address1" id="address1">
</div>

<BR>
<button type="submit" class="btn btn-default">Submit</button>
</form>
Rephrasing and more clarification.
Source Link

How to add Adding featured images fromimage to a new post using front-end form?

I have a code that createsHave a custom post type from front-end form. But it to create a post, Was only savesable to add text data like title andto the new post (title, content, text-typed custom fields). What should I add to this codewant to be ableadd a featured image to save imagesthe new posts too?.

PIt's a WordPress site and I use Avada theme.S The custom post type is the Avada's default Portfolio post. So, I can'twant the code to work on that post type. (Couldn't use plugins like Post My CF7 Form. They didn't work on my website. I haveNeed to write code.)

Please add some code to my PHP code and the form so that it can save a featured image too.

So, Here's my php code in fuctions.php in my child-theme:

///////////////////////////////////////
///How to submit custom post type in wordpress from the Front-End

if(isset($_POST['title'])){


//echo $_POST['title']; // print title variable value

// create post object

$custom_field_add1 = $_POST['add1'];
$custom_field_phone = $_POST['phone'];


$my_post = array(

'post_title' => $_POST['title'],
'post_content' => $_POST['description'],
    
'post_status' => 'publish', 
'post_type' => 'companies',
'meta_input' => array(
    'add1' => $custom_field_add1,
    'phone' => $custom_field_phone,
    )
);


// i use wordpres predefine function/
$post_id = wp_insert_post($my_post);
///

add_post_meta( $post_id, 'add1', $custom_field_add1, false );
add_post_meta( $post_id, 'phone', $custom_field_phone, false );
echo 'New Post Saved !';

die; // stop script after form submit
}

My CF7 form:

<div class="form-group">
      <label for="title">Post Title:</label>
      <input type="text" class="form-control" id="title" name="title">
    </div>
    
    
    <div class="form-group">
      <label for="pwd">Description (Post content):</label>
      <textarea class="form-control"  name="description"></textarea>
    </div>


      <div class="form-group">
      <label for="add1">Address:</label>
      <input type="text" name="add1" id="add1">
    </div>
    
      <div class="form-group">
      <label for="phone">Phone:</label>
      <input type="number" name="phone" id="phone">
    </div>

    <BR>
[submit]

How to add featured images from front-end?

I have a code that creates a custom post type from front-end form. But it only saves text data like title and the content. What should I add to this code to be able to save images too?

P.S I can't use plugins like Post My CF7 Form. They didn't work on my website. I have to write code.

///////////////////////////////////////
///How to submit custom post type in wordpress from the Front-End

if(isset($_POST['title'])){


//echo $_POST['title']; // print title variable value

// create post object

$custom_field_add1 = $_POST['add1'];
$custom_field_phone = $_POST['phone'];


$my_post = array(

'post_title' => $_POST['title'],
'post_content' => $_POST['description'],
    
'post_status' => 'publish', 
'post_type' => 'companies',
'meta_input' => array(
    'add1' => $custom_field_add1,
    'phone' => $custom_field_phone,
    )
);


// i use wordpres predefine function/
$post_id = wp_insert_post($my_post);
///

add_post_meta( $post_id, 'add1', $custom_field_add1, false );
add_post_meta( $post_id, 'phone', $custom_field_phone, false );
echo 'New Post Saved !';

die; // stop script after form submit
}

Adding featured image to a new post using front-end form?

Have a front-end form to create a post, Was only able to add text data to the new post (title, content, text-typed custom fields). I want to add a featured image to the new posts too.

It's a WordPress site and I use Avada theme. The custom post type is the Avada's default Portfolio post. So, I want the code to work on that post type. (Couldn't use plugins like Post My CF7 Form. They didn't work on my website. Need to write code.)

Please add some code to my PHP code and the form so that it can save a featured image too.

So, Here's my php code in fuctions.php in my child-theme:

///////////////////////////////////////
///How to submit custom post type in wordpress from the Front-End

if(isset($_POST['title'])){


//echo $_POST['title']; // print title variable value

// create post object

$custom_field_add1 = $_POST['add1'];
$custom_field_phone = $_POST['phone'];


$my_post = array(

'post_title' => $_POST['title'],
'post_content' => $_POST['description'],
    
'post_status' => 'publish', 
'post_type' => 'companies',
'meta_input' => array(
    'add1' => $custom_field_add1,
    'phone' => $custom_field_phone,
    )
);


// i use wordpres predefine function/
$post_id = wp_insert_post($my_post);
///

add_post_meta( $post_id, 'add1', $custom_field_add1, false );
add_post_meta( $post_id, 'phone', $custom_field_phone, false );
echo 'New Post Saved !';

die; // stop script after form submit
}

My CF7 form:

<div class="form-group">
      <label for="title">Post Title:</label>
      <input type="text" class="form-control" id="title" name="title">
    </div>
    
    
    <div class="form-group">
      <label for="pwd">Description (Post content):</label>
      <textarea class="form-control"  name="description"></textarea>
    </div>


      <div class="form-group">
      <label for="add1">Address:</label>
      <input type="text" name="add1" id="add1">
    </div>
    
      <div class="form-group">
      <label for="phone">Phone:</label>
      <input type="number" name="phone" id="phone">
    </div>

    <BR>
[submit]
Source Link
Loading