0

I'm trying to save a custom post type from the frontend using Gravity Forms (v2.0.6). This post type has custom fields expecting a term ID.

One of the fields is about a "Food Type", and I have like 5 terms on that taxonomy. I have tried with a simple Dropdown field, which allows to "Populate with a Taxonomy" (or a Post Type), but this field type can't be saved as a custom field of the custom post type.

So, what I want is to have this function:

Populate with a Taxonomy

[...] available in the "Custom Field" field type.

This field needs to show the term name, but the option value needs to be the term id, because the custom field in the post type expects the term ID.

Is this possible? Thanks in advance!

1
  • Questions about the workings of a specific plugin are better directed at the plugin's author.
    – cjbj
    Aug 13, 2016 at 12:12

1 Answer 1

1

For anyone who needs help with this, here's my solution.

With the Gravity Forms hooks gform_pre_render, gform_pre_validation, gform_pre_submission_filter and gform_admin_pre_render I was able to populate the dropdown fields with dynamic data.

Despite this is not too user friendly, we can define specific CSS classes to have this done and avoid populate fields that we don't want to.

Basically what we do is create a function that renders the form. But first, as I mentioned above, to avoid populate the incorrect fields, we validate that is the correct field type (Important: with custom fields, the type is custom_field instead select [as the tutorial describes]. To target custom fields of type dropdown/radio, set the type to custom_field and the field_type to select), and the correct CSS class.

Then, instead of using get_posts, we use get_terms to retrieve the terms.

Hope this helps someone.

Not the answer you're looking for? Browse other questions tagged or ask your own question.