Post forms (create or edit a post)
4 min read
The kind Post (create or edit) creates a post when submitted, and saves the values of the chosen field groups for that post exactly like the post's edit screen. The same form can edit an existing post.
Typical uses: an event submission form, a directory listing, a guest article, a member's "edit my listing" page.
The Posts card
Setting | Default | Notes |
|---|---|---|
Post type | Post | Any public post type except Media (Pages, your custom post types ...). |
Status of new posts | Pending review | Pending review, Draft or Published. Help: ""Published" applies only to users who may publish; everyone else's posts wait for review." |
Title field | on | Shows a Title box. Required. With it off, the post gets a title made from the form title and the date, for example |
Content field | off | Shows a Content text area (plain text box, eight lines). |
Below the settings the card says: "The form creates a post. To edit one, add post_id="123" to the shortcode or link to the page with ?wpmcf_edit=123; only users who may edit that post see it."
The field values come from the field groups you ticked in the Fields card (Create a form). A field group needs a location rule (any rule) so that its values can be stored per post.
What the visitor sees
- A Title box (marked required), an optional Content box, then the groups' fields. With more than one group each group is a fieldset with its name as the legend.
- A button Submit (or your Button label).
- After a successful submission the Success message replaces the form (default "Thank you! Your entry has been received.").
What is created
- A post of the chosen type with the chosen status. Published is applied only when the submitter's role may publish posts of that type; every other submitter gets Pending review, so a guest or subscriber can never publish by themselves.
- The post author is the logged-in user, or no author (
0) for a guest. - The title is saved as plain text. The content is cleaned like a comment (
wp_kses_post), and for submitters who cannot edit posts (guests, subscribers)[,]and HTML comment markers are neutralised, so a visitor cannot plant shortcodes or dynamic blocks that would run once an editor publishes the post. - The field group values are saved to the post's row, and Taxonomy fields assign their terms.
- Uploaded files go to the Media Library attached to the post (File uploads).
- Optionally an email to you (Notifications); its link opens the post's edit screen.
Edit an existing post
The same form edits a post when it is told which post:
[wpmcf_form key="submit_event" post_id="123"]shows the form filled with post 123 (the block has the same option, Edit post ID, help "Post forms only: the post to edit. Leave empty to create posts."), or- a link to the page with
?wpmcf_edit=123at the end (https://example.com/edit-event/?wpmcf_edit=123).
The post is loaded only when all are true: the visitor is logged in, the post is of the form's post type, and WordPress lets the visitor edit that post (edit_post). Otherwise the form says "You are not allowed to edit this entry." and shows nothing else. The same checks run again when the form is submitted, so changing the ID in the browser does not help.
An editing form:
- shows the current title, content and values; the button reads Save changes;
- keeps the post's status (editing never changes it) and updates the title, content and values;
- stays on the page after saving and shows the success message above the form.
To give members a list of their posts with an edit link, build the link yourself, for example in a template: add_query_arg( 'wpmcf_edit', $post->ID, home_url( '/edit-event/' ) ).
Who may use the form
Set it in Who can submit: Anyone, including visitors, Logged-in users or Users with a capability. For editing, the visitor must in any case be logged in and allowed to edit the post, whatever you chose. See Guests and spam protection.
Limits
- One post type per form. Make two forms for two types.
- The form does not offer a featured image, excerpt, slug, date or categories by itself. Add a field group with an Image field (stored as a field value, not as the featured image) or a Taxonomy field for terms.
- Field types that cannot work on a public page are left out; see the overview.
- A post form does not edit posts of other users unless WordPress's own permissions allow it.
Still stuck? Contact support