Create post and update post meta from front end


<?php
$post_title = $_POST[‘post_title’];
$post_data = $_POST[‘post_data’];
$user_id = get_current_user_id();
$post_type = “gallery”;
$my_post = array(
  ‘post_title’    => $post_title,
  ‘post_content’  => $post_data,
  ‘post_status’   => ‘publish’,
  ‘post_author’   => $user_id,
  ‘post_type’ => $post_type
);
$post_id = wp_insert_post( $my_post );
update_post_meta($post_id, ‘_name’, $img);
?>
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s