Ah Gravity Forms. Shall I compare thee to a summer’s day? Probably not. But I’m a huge fan of the plugin that gives so much power in building forms. I’ve used it for so much in my time in WordPress, that right now I’m confident if I need anything from a booking form to a custom search engine, Gravity Forms is my go to form.
One example I quite like is using Gravity Forms & Custom Post Types together to build something incredible. This is a go-to method for building any functionality, as it’s so expandable and extensible. In this article I’ll show you how to use Gravity Forms & Custom Post Types together to build a front end award nominators, allowing users to submit nominee into a custom post type.
Build the Custom Post Type
Now, usually I’d build these into code, but for this example, I’m going to use two plugins – one to create the custom post type (Custom Post Type UI), one to create the custom fields we’d be using with this custom post type (Advanced Custom Fields). In Custom Post Type UI plugin create your custom post type (I called it “nominee”). Make sure the “Custom Fields” checkbox in “Supports” is selected, and then click “Save Post Type”.
Now Install “Advanced Custom Fields” and go to Custom Fields. Create a custom field group and make sure you give it a few custom fields. Add a rule so that you show the field group if Post Type is equal to “nominees” and then click “Publish”.
Your custom post type should now be present in the sidebar, try creating a new post to make sure that it all works.
Install Gravity Forms & Custom Post Type Plugin
Now we need Gravity Forms as well as a helper plugin. Install Gravity Forms and the Gravity Forms + Custom Post Type Plugin. This plugin is freely available on the WordPress Repository so be sure to install both. Now we will create our form.
Create Your Gravity Form to Hook into Your Custom Post Type
Once installed create a form in Gravity Form. You’re going to need the following fields at the very least.
This is under the “Post” Group and you need to make sure that when you place it you assign it a Post Type.
This will be the main body of the custom post type. If you don’t have any body text you can skip this but otherwise add one in as it makes creating a template easier.
What I do here is use the test post created in the previous step to populate the “Custom Field Name” drop down. This removes the guess work in creating fields, but you will need to manually match up your custom field type in Gravity Forms with your custom field type created in ACF. This could lead to problems if you have checkboxes, select boxes or radio buttons and the names don’t match, so make sure they do.
Place The Form On The Front End
Now you need to place the Gravity Form on a page or post within your site. To do so go to the page or post that you wish to put your form on and click the “Add Form” button. Select the form and a shortcode will appear on that page. Update the page or post and go onto the next step.
Finally, get testing! Go to the page and try filling out the form. Click “Submit” when done.
Then return to the admin section and go to your post type, you should see your post that you submitted there all ready to be worked with!
It should be added that custom fields, whilst present, are unlikely to show on the front end unless you do some template work, but that is how you can use Gravity Forms & Custom Post Types together to allow people to submit custom post types.