Last active
April 28, 2023 08:33
-
-
Save mattiasghodsian/a6ecf354bdb09dd0df8b274606127325 to your computer and use it in GitHub Desktop.
[WordPress] Get field data by field ID gravity forms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* gf_get_field_data | |
* Author: Mattias Ghodsian | |
* Donate a cup of coffee: https://www.buymeacoffee.com/mattiasghodsian | |
* Donate Eth: 0xBBB96204E45D11C9799c6B12E6eE6F0d4A071Ef5 | |
* | |
* @param int $form_id | |
* @param int $id the field integer key | |
* @param str $key what value to return | |
* @return string/boolean | |
*/ | |
function gf_get_field_data( int $form_id, int $id, $val){ | |
global $wpdb; | |
if ( !is_string($val) ) | |
return "$val must be a string"; | |
$t = $wpdb->prefix.'gf_form_meta'; | |
$q = $wpdb->get_var( "SELECT display_meta FROM {$t} WHERE form_id = {$form_id}" ); | |
if ( !$q ) | |
return false; | |
$q = json_decode($q); | |
foreach ($q->fields as $key => $d) { | |
if ($d->id == $id) { | |
return $d->{$val}; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example
This returns the label Namn of field id 3 of form id 1
What you can expect to return