Get value from another wordpress table

Est. Reading: 1 minute
By: FDM Digital
Created: 06/22/2018
Category:
Difficulty: Intermediate

Get value from another wordpress table

×Warning: This tutorial was created 2347 days ago. Some of the information may be out of date with more recent versions of Formidable. Please proceed with caution and always perform a backup before adding custom code.

Hi All,

This snippet can be used to get a value from another database table and insert it as the default value of a form field.

// Get Remaining Shares
add_filter('frm_get_default_value', 'my_custom_default_value', 10, 2);
function my_custom_default_value($new_value, $field){
if($field->id == 25){ //change 25 to the ID of the field
global $wpdb;
$user = wp_get_current_user();
$new_value = $wpdb->get_var("SELECT SUM(Shares_Remaining) FROM UserSummaryByYear WHERE user_name='$user->user_login'");
}
return $new_value;
}

 

Notes:

  1. Change 25 to the ID of the field you want to insert the value into
  2. Change SUM(Shares_Remaining) to the name (or sum of) the column you wish to search
  3. Change UserSummaryByYear to the name of the db table
  4. This example checks the UserSummaryByYear table for the 'user_name' column and compares it to the users WordPress login. Edit as required.

Thanks

Chris

Leave a Reply

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crosschevron-leftchevron-rightarrow-right