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!
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.