// Find a field value in another form's entries, based on the user ID
// usage example: [frm-field-value-from-another-form form_id=5 field_id=465 prefix="Pt 3 Status:" user_id=[411 show="ID"]]
add_shortcode( 'frm-field-value-from-another-form', 'frm_find_field_value_from_another_form_using_user_id' );
function frm_find_field_value_from_another_form_using_user_id( $atts ) {
$atts = shortcode_atts(
array(
'user_id' => '',
'form_id' => '',
'field_id' => '',
'prefix' => '',
), $atts, 'frm-field-value-from-another-form' );
$thisFieldValue = '';
$prefixText = '';
$userID = $atts['user_id'];
$formID = $atts['form_id'];
$fieldID = $atts['field_id'];
if ( $atts['prefix'] != '' ) { $prefixText = $atts['prefix'] . ' '; }
if ( $userID != '' ) {
global $wpdb;
$entryID = $wpdb->get_col( "SELECT id FROM {$wpdb->prefix}frm_items WHERE form_id = '{$formID}' AND user_id = '{$userID}'" );
// If there's no Entry ID (Community has no Actions) then don't do anything more
if ( count($entryID) > 0 ) {
$fieldType = $wpdb->get_col( "SELECT type FROM {$wpdb->prefix}frm_fields WHERE id = '{$fieldID}'" );
$fieldType = $fieldType[0];
$entryID = $entryID[0];
$entryValue = $wpdb->get_col( "SELECT meta_value FROM {$wpdb->prefix}frm_item_metas WHERE field_id = '{$fieldID}' AND item_id = '{$entryID}'" );
if ( count($entryValue) > 0 ) {
$thisEntryValue = $entryValue[0];
// For dynamic fields that store a number and get their display text from anther form
if ( $fieldType == 'data' ) {
$thisEntryValue = $wpdb->get_col( "SELECT meta_value FROM {$wpdb->prefix}frm_item_metas WHERE item_id = '{$thisEntryValue}'" );
$thisEntryValue = $thisEntryValue[0];
}
$thisFieldValue = $prefixText . $thisEntryValue;
}
}
}
return $thisFieldValue; // Value of the field
}