search/update entries by meta value - PHP

By: Henning Jønsson | Asked: 06/25/2024
ForumsCategory: Code Snippetssearch/update entries by meta value - PHP
Henning Jønsson asked 4 weeks ago
I have the code below that I want to change so that it can search for values ​​in the database on the field ID.

Form B contains (Form ID 11)
name
last name
permission (Field ID 89)
CVR (unique)

Form A contains (Form ID 12)
CVR (unique) (Field ID 117)
name
last name

When form A submitting, I will look for already created forms in form B, which contain the CVR number.
take the CVR number from form A and add it in the permission field in form B.

Help :)


Start your code here
add_action('frm_after_create_entry', 'update_or_create_entry', 30, 2); add_action('frm_after_update_entry', 'update_or_create_entry', 10, 2); function update_or_create_entry($entry_id, $form_id){ if ( $form_id == 12 ) {//Change 12 to the ID of Form A - ID 12 = firma - tilknyt kunde global $wpdb; $CVR = $_POST['item_meta'][117]; $total = "test13"; $form2 = '11';//Change 11 to the ID of Form B - ID 11 //Get user and their total $user = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM {$wpdb->prefix}frm_items WHERE id=%d", $entry_id)); if ( !$user ) { return; } //$total = FrmProStatisticsController::stats_shortcode(array('id' => 87, 'type' => 'count', 'user_id' => $user));//Change 47914 with the ID of the field that you want to total //See if this user already has an entry in second form //$entry_id = $wpdb->get_var("Select id from {$wpdb->prefix}frm_items where form_id='" . $form2 . "' and user_id=". $user); $entry_id = $wpdb->get_var("Select id from {$wpdb->prefix}frm_items where form_id='" . $form2 . "' and item_key=". $CVR); if ( $entry_id ) { //update entry $wpdb->update( $wpdb->prefix . 'frm_item_metas', array('meta_value' => $total), array('item_id' => $entry_id, 'field_id' => '89'));//Change 48262 to the ID of the field you want to populate in Form B - 89 = } else { //Do nothing ), )); } } }

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
crossarrow-right