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
- Edit your form > Actions tab > Add Action > Create WordPress Post.
- Select the post type and status.
- Configure title and content sources.
- 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:
- Title Field -- if set and the field has a value, uses it directly.
- Title Template -- if set, processes
[field_name]variables (e.g.,[name] -- Submission from [CF_TIMESTAMP]). - Fallback --
{Form Title} -- {timestamp}.
Content Resolution
Content is determined in this order:
- Content Field -- if set, uses the field value (HTML allowed via
wp_kses_post()). - 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
- Validates that the post type exists (falls back to
post). - Resolves the title from field, template, or fallback.
- Resolves the content from field or auto-generated summary.
- Creates the post via
wp_insert_post(). - Processes meta field mappings and saves each as post meta.
- Stores
_cf_submission_idfor reference. - Returns
trueon 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.