Skip Navigation

[Resolved] Populate Gravity Form Select Field with Custom Post's custom field

This support ticket is created 6 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Beda 6 years, 4 months ago.

Assisted by: Beda.

Author
Posts
#605889

I have a custom post type called Attorneys. I've added a custom post field called email. I am trying to populate the dropdown of a Gravity Form with those values. Essentially:

<option value="[wpcf-email]">Custom Post Title</option>

I'm using this snippet:
hidden link

Which gives me:
<option value="Custom Post Title">Custom Post Title</option>

I'm a little stuck trying to retrieve the custom value from the email field. (I'm using the email field type.)

Any idea how I might do this?

Thanks!

#605949

The snippet is not from our API, and that restricts my possibilities here in support.

I see the snippet populates the array $choices[] with values from a get_posts().
It uses get_the_title() to get the Posts Title, you should be able to use a simple get_post_meta() in this array, to get the custom field of Types.

No matter where you are going to use the value, you can retrieve the value of a Types Custom Field in 3 ways:
- by ShortCode (Not suitable for your goal)
- by Types API, using types_render_field().
https://toolset.com/documentation/customizing-sites-using-php/functions/
- by WordPress API, using get_post_meta().
https://developer.wordpress.org/reference/functions/get_post_meta/

Both will work fine for your project.
I suggest to use the WordPress API, as our Types API is just calling the WordPress function.

You can populate a $variable with the values you get and use that in your $choices[] array.
You will need to pass the Post ID to get_post_meta().
You should be able to get this value from the post object, which should be stored in $movie_id, with $movie_id->ID.

I would quickly ensure that you receive correct values (no HTML along the value) by var_dump() your $variable, as well as doubleproof $movie_id->ID, so you can be sure you get what you expect.

I unfortunately will not be allowed to write this snippet for you, this does not involve our API.

If you require more help in getting the Types Fields values, please do not hesitate to ask for more details.

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.