Contact me if you need to build a complex form with complex functions by using Caldera Forms (Create new user, send SMS to user, email validation, delete user, delete post...)In this tutorial, I will show you one of the most powerful weapon of Caldera Forms – Run Action. You can do lots of stuffs with this superb tool, I list here something you can think of:

  • Sending Emails to Members which their profile meet some criteria (“job” = “teacher”…)
  • Send SMS to Admin/ Members…
  • Create a new post, insert new user…

To demonstrate, I will show you how to use Run Action to create a new post from Form’s fields (which we can do easily with Caldera Custom Fields Plugin in WordPress repository)

Set up a Guest Post Form

In order to use Run Action to create new post we will make a form in which:

  • 1 Single Line Text Field, Slug = title
  • 1 Paragraph Text Area Field, Slug = content
  • 1 Button

Caldera Forms Guest Post

Install and Set up Run Action

You can install Run Action from WordPress repository.  There will be 1 more processor in your Caldera Forms’ settings. Pick Run Action processor, some settings:

  • Position = Post-Process
  • Type = Action
  • Action/Filter = add_new_post

Caldera Forms Run Action

Create new guest post as form submitted

In order to create a new post, we will use this code snippet

add_action( 'add_new_post', 'add_new_guest_post');
function add_new_guest_post($data) {
  global $user_ID;
  $new_post = array(
  'post_title' => $data['title'],//Get Title from form
  'post_content' => $data['content'],// Get content from form
  'post_status' => 'publish',
  'post_date' => date('Y-m-d H:i:s'),
  'post_author' => $user_ID,
  'post_type' => 'post',
  'post_category' => array(0)
  );
  $post_id = wp_insert_post($new_post);

}

If all goes well, after click Send Post we will have a new guest post. You can change post_status to pending/ draft for review before publish…

Guest Post

 

Credit:

GiangLe.DEV

My name is Giang, a Vietnamese guy living in Thanh Hoa City, Vietnam. I am a WordPress Developer, learning to master WordPress and Laravel PHP Framework.

2
Leave a Reply

avatar
1 Comment threads
1 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
GiangLe.DEVjesus Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
jesus
Guest

Thanks for sharing

Close Menu