Skip to main content

Create WordPress Post Integration

Create a new post or custom post type entry from form data when a form is submitted.

Action type: create_post Class: Core_Forms\Actions\CreatePost Source: src/actions/class-create-post.php

Setup

  1. Edit your form > Actions tab > Add Action > Create WordPress Post.
  2. Select the post type and status.
  3. Configure title and content sources.
  4. Optionally map form fields to custom meta fields.

Settings Reference

Setting Required Default Description
Post Type No post Any registered public post type
Post Status No draft draft, pending, publish, or private
Title No -- Template with [field] variables for the post title
Title Field No -- Form field to use directly as the post title
Content Field No -- Form field to use as post content
Custom Fields No -- Map form fields to post meta keys

Title Resolution

Title is determined in this order:

  1. Title Field -- if set and the field has a value, uses it directly.
  2. Title Template -- if set, processes [field_name] variables (e.g., [name] -- Submission from [CF_TIMESTAMP]).
  3. Fallback -- {Form Title} -- {timestamp}.

Content Resolution

Content is determined in this order:

  1. Content Field -- if set, uses the field value (HTML allowed via wp_kses_post()).
  2. Fallback -- all form fields formatted as <strong>Label:</strong> Value, one per line.

Custom Fields (Meta Mapping)

One mapping per line, form_field=meta_key:

email=_contact_email
phone=_contact_phone
company=_company_name

Values are sanitized with sanitize_text_field() and meta keys with sanitize_key(). Array values (checkboxes) are joined with commas.

Submission Reference

Every created post stores _cf_submission_id as post meta, linking back to the original form submission ID.

How It Works

  1. Validates that the post type exists (falls back to post).
  2. Resolves the title from field, template, or fallback.
  3. Resolves the content from field or auto-generated summary.
  4. Creates the post via wp_insert_post().
  5. Processes meta field mappings and saves each as post meta.
  6. Stores _cf_submission_id for reference.
  7. Returns true on success.

Example: Guest Blog Submission

Form with title, content, author_name, and email fields:

  • Post Type: post
  • Post Status: pending
  • Title Field: title
  • Content Field: content
  • Custom Fields: author_name=_guest_author email=_guest_email

Example: Support Ticket

Form with subject, description, priority, and email fields:

  • Post Type: support_ticket (custom post type)
  • Post Status: publish
  • Title Field: subject
  • Content Field: description
  • Custom Fields: priority=_ticket_priority email=_submitter_email

Troubleshooting

  • Post type not in dropdown: Only public post types appear. Register your CPT with 'public' => true.
  • HTML stripped from content: Content is filtered through wp_kses_post(), which allows safe HTML tags but strips scripts and unsafe attributes.
  • Meta key not appearing: Meta keys are sanitized with sanitize_key(), which lowercases and removes special characters. Use lowercase keys with underscores.

See Also

For more advanced post creation with taxonomy, ACF, and featured image support, use the Create Article integration.