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.

Populate a Drop with Categories from Current Post

  1. Hi,

    What I want to do is populate a dropdown field with categories from the current post.

    Basically it is for a website for custom rims, each rim will be a custom post type / product categories by style, brand and rim size. Some rims only have 20" or 22", so the size will be a sub cat of the parent rim size. I want to display only the rim size in a drop down, so a user fills out a online quote form on the same page as the rim and selects they= size they want 20" or 22". Make sense? Same as this: http://www.ozzytyres.com.au/wheels/initial-d-black-red-stripe/

    Posted 13 years ago on Thursday September 1, 2011 | Permalink
  2. Anyone?

    Posted 13 years ago on Friday September 2, 2011 | Permalink
  3. Here's an explanation of how to dynamically populate a drop down:
    http://www.gravityhelp.com/documentation/page/Dynamically_Populating_Drop_Down_Fields

    You will need to use the gform_pre_render hook and the WordPress function get_the_category.

    I created an example here:
    http://gravity.chrishajer.com/2011/09/02/inquire-about-rims/

    Here's the code I used:
    http://pastebin.com/ynTTJqu7

    Change the 33 on line 3 of this code to your form ID. Also, see line 10 for the CSS Class Name to use to "tag" your select box to be targeted by this function (I used populate-categories, which you enter on the advanced tab of your drop down, in the form builder. You can also change the "instructive option" on line 15. I used "Rim Size" but you can change that and see how it affects the display and validation of the drop down.

    If you have more questions, please let us know.

    Posted 13 years ago on Friday September 2, 2011 | Permalink