PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Custom taxonomy checkbox code

  1. Anonymous
    Unregistered

    Thought I should share - here is my code for adding custom taxonomies to forms that create posts. The taxonomies show up in the form as a set of checkboxes, and the selected terms are saved into the WP post data. This is nice because it automatically fills in the available taxonomies, and it allows you to select more than one option.

    CODE: http://www.pastie.org/1485769

    Things to note:

    Checkboxes in Gravity are a little tricky. In order for this to work, first I created the checkboxes in the form admin, but did not add any options. You must have the fields be checkboxes though or it won't work. Also, Gravity saves each checkbox value separately - if your checkbox is field 1, each checked box will be saved separately in the form entry data array as 1.1=> muffin, 1.5=> cookie, etc. To capture them all I had to use a foreach and substr to get all of the selected values out of the entry data array.

    I had two different taxonomies and two different forms - one using only one tax, one using both of them. I did this with simple if statements and a switch.

    Hope this helps somebody! And if there is a more efficient way to do this, do let me know :)

    Inspiration for this code was found here:
    http://forum.gravityhelp.com/topic/automatically-populate-a-dropdown-with-post-titles
    http://forum.gravityhelp.com/topic/custom-taxonomies-for-multiple-forms

    Posted 13 years ago on Friday January 21, 2011 | Permalink