Skip to content
Advertisement

How to add multiple submit buttons in ACF form?

I’m using ACF Form in Front-end of a WordPress website. It is used to create a custom posts in WordPress. I need to add two submit buttons in this ACF Form. when i click the first button, it should create a new post and post status should be publish and when I click the another button, it should create a new post and post status should be draft.

My code below will create a post with status as published. How can i achieve this?

JavaScript

Advertisement

Answer

It is possible achieve this using the hidden field and a bit of jQuery.

Step 1: You need to add the hidden field and set default value as 1.

JavaScript

Step 2:

Use the below code near the form and then append this field to the form using jQuery.

JavaScript

Step 3: When Clicking on the “Draft” button overwrite its value as 2.

JavaScript

Step 4: Add the below code in fucntions.php which will change the post status based on the button which we click.

JavaScript

We have added both the ‘Publish’ and ‘Save as Draft’ buttons in a single ACF form.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement