Is there a way to have 2 submit buttons, one that has actions of Create Post/Update post meta fields and the other Update Post/update post meta fields?
I want this so the user can edit an existing post or save an existing post as a new post having made some changes (the equivalent of duplicating a post and updating some fields).
Hi Pete,
Not via two submit buttons, unfortunately. The submit button carries no action configuration of its own - it renders as a plain submit button, and the actions are configured once for the whole form, so every button inside that form runs the same list.
The feature that gets you the same result is Action Conditions. Add both actions to the form (Create New Post and Update Post), then go to Actions and enable “Action Conditions”. Add one row per action, for example: Action = Update Post, Condition = Form Field, Value = the ID of your mode field, Is Equal, “update” - and a second row with Action = Create New Post, same field, Is Equal, “new”. Any action whose condition does not match is dropped before anything is executed, so exactly one of the two runs.
For the choice itself use a normal field instead of a second button - a Radio or Select with two options such as “Save changes” and “Save as a new copy”. If you style the two radios as buttons, you end up visually where you wanted to be, with one submit button below.
Kind regards
Daniele
Thanks for this Daniele, what I am not sure of is if the user wants to create a new post, the update meta action needs the {{live_post_id}} but if the update post meta is part of an update post workflow, the the saved postid field suffices. As the conditions are whether an action runs or not, I cannot use that. Would something like {{my-post-id-field}}{{live_post_id}} work as I could have a JS that clears the postid form field so it would be blank?
Rewgards
Pete
Also, in the situation where it is an Update Post only, does the Update Post action need to be present if I know the postid and not need the {{live_post_id}}?
Hi Pete,
good questions - and the good news is you do not need the concatenation trick.
{{live_post_id}} is not tied to Create New Post. The Update Post action sets it as well, right after the post has been updated successfully. So in both branches - “save as a new copy” and “update the existing post” - {{live_post_id}} carries the ID of the post that branch just touched, and Update Post Meta always runs after both of them. Put {{live_post_id}} into the Post ID of every meta row and you are done. No JS to clear a field.
For the record, {{my-post-id-field}}{{live_post_id}} would not have worked: the live-ID handling only kicks in when the Post ID is exactly {{live_post_id}}. Anything else goes through the normal field parsing, where the tag is replaced inline - you would end up with both numbers glued together into one invalid ID.
The one condition is that {{live_post_id}} is only filled if the action really succeeded. If Update Post is stopped by its permission checks, it stays empty.
To your second question: no, Update Post is not required. Update Post Meta is a standalone action - every meta row has its own Post ID field, and a static ID or a form field tag works there just as well. You only need Update Post if you also want to change the title, content, status, date, taxonomies or the thumbnail.
One thing to watch out for in your setup: if the form is rendered with a dynamic post ID, for example inside a query loop, that ID takes precedence over whatever you put into the row’s Post ID - unless the value is exactly {{live_post_id}}.
Kind regards
Daniele