fetch all row values with same user id in php? - php

I am working on wordpress website and i just stuck over one sql query.
I need to get the values from database table which contain same user id.
here is my table:
And when i run select query in mysql it is fetching result correct:
But i dont know how to get this result in my php template.
this is my query i am using in php:
$current_user = wp_get_current_user();
$id=$current_user->ID;
$skill1 =mysql_query("SELECT Skills FROM wp_candidate_skills WHERE user_id='{$id}' ");
I cant use get->result because it is showing error that get->result must contain object. Something like this error is.
This is what i am using after Mysql_query:
$arr = mysql_fetch_array($skill1);
print_r($arr);
And the Output is:
Wordpress code:
public static function init_fields() {
if ( self::$fields )
return;
$current_user = wp_get_current_user();
$user = $current_user->user_login;
$useremail = $current_user->user_email;
$id=$current_user->ID;
$skill1 =mysql_query("SELECT ID,user_id,Skills FROM wp_candidate_skills WHERE user_id=$id");
$skill_note = mysql_fetch_array($skill1);
$result = mysql_query("SELECT * FROM wp_candidate_details WHERE user_id='{$id}' LIMIT 1");
$expe_note = mysql_fetch_assoc($result);
$job_title = $expe_note['job-cat1'];
$user_loc = $expe_note['location_one_id'];
$row_num = mysql_query("SELECT COUNT(Skills) FROM wp_candidate_skills WHERE user_id='{$id}' " );
$row_cnt = mysql_fetch_array($row_num);
$arr = mysql_fetch_array($skill1);
print_r($arr);
mysql_free_result($skill1);
$skill_area = $skill_note['Skills'];
self::$fields = apply_filters( 'submit_resume_form_fields', array(
'resume_fields' => array(
'candidate_name' => array(
'label' => __( 'Your name', 'wp-job-manager-resumes' ),
'type' => 'text',
'required' => true,
'placeholder' => __( 'Your full name', 'wp-job-manager-resumes' ),
'priority' => 1,
'value' => $user
),
'candidate_email' => array(
'label' => __( 'Your email', 'wp-job-manager-resumes' ),
'type' => 'text',
'required' => true,
'placeholder' => __( 'you#yourdomain.com', 'wp-job-manager-resumes' ),
'priority' => 2,
'value' => $useremail
),
'candidate_title' => array(
'label' => __( 'Professional title', 'wp-job-manager-resumes' ),
'type' => 'text',
'required' => true,
'placeholder' => __( 'e.g. "Web Developer"', 'wp-job-manager-resumes' ),
'priority' => 3,
'value' => $job_title
),
'candidate_location' => array(
'label' => __( 'Location', 'wp-job-manager-resumes' ),
'type' => 'text',
'required' => true,
'placeholder' => __( 'e.g. "London, UK", "New York", "Houston, TX"', 'wp-job-manager-resumes' ),
'priority' => 4,
'value' => $user_loc
),
'resume_skills' => array(
'label' => __( 'Skills', 'wp-job-manager-resumes' ),
'type' => 'text',
'required' => false,
'placeholder' => __( 'Comma separate a list of relevant skills', 'wp-job-manager-resumes' ),
'priority' => 9,
'value' => $skill_area
),
'links' => array(
'label' => __( 'URL(s)', 'wp-job-manager-resumes' ),
'type' => 'links',
'required' => false,
'placeholder' => '',
'description' => __( 'Optionally provide links to any of your websites or social network profiles.', 'wp-job-manager-resumes' ),
'priority' => 10,
'fields' => array(
'name' => array(
'label' => __( 'Name', 'wp-job-manager-resumes' ),
'type' => 'text',
'required' => true,
'placeholder' => '',
'priority' => 1
),
'url' => array(
'label' => __( 'URL', 'wp-job-manager-resumes' ),
'type' => 'text',
'required' => true,
'placeholder' => 'http://',
'priority' => 2
)
)
),
'candidate_education' => array(
'label' => __( 'Education', 'wp-job-manager-resumes' ),
'type' => 'education',
'required' => false,
'placeholder' => '',
'priority' => 11,
'fields' => array(
'location' => array(
'label' => __( 'School name', 'wp-job-manager-resumes' ),
'type' => 'text',
'required' => true,
'placeholder' => ''
),
'qualification' => array(
'label' => __( 'Qualification(s)', 'wp-job-manager-resumes' ),
'type' => 'text',
'required' => true,
'placeholder' => ''
),
'date' => array(
'label' => __( 'Start/end date', 'wp-job-manager-resumes' ),
'type' => 'text',
'required' => true,
'placeholder' => ''
),
'notes' => array(
'label' => __( 'Notes', 'wp-job-manager-resumes' ),
'type' => 'textarea',
'required' => false,
'placeholder' => ''
)
)
),
'candidate_experience' => array(
'label' => __( 'Experience', 'wp-job-manager-resumes' ),
'type' => 'experience',
'required' => false,
'placeholder' => '',
'priority' => 12,
'fields' => array(
'employer' => array(
'label' => __( 'Employer', 'wp-job-manager-resumes' ),
'type' => 'text',
'required' => true,
'placeholder' => ''
),
'job_title' => array(
'label' => __( 'Job Title', 'wp-job-manager-resumes' ),
'type' => 'text',
'required' => true,
'placeholder' => ''
),
'date' => array(
'label' => __( 'Start/end date', 'wp-job-manager-resumes' ),
'type' => 'text',
'required' => true,
'placeholder' => ''
),
'notes' => array(
'label' => __( 'Notes', 'wp-job-manager-resumes' ),
'type' => 'textarea',
'required' => false,
'placeholder' => ''
)
)
),
'resume_file' => array(
'label' => __( 'Resume file', 'wp-job-manager-resumes' ),
'type' => 'file',
'required' => false,
'description' => sprintf( __( 'Optionally upload your resume for employers to view. Max. file size: %s.', 'wp-job-manager-resumes' ), size_format( wp_max_upload_size() ) ),
'priority' => 13,
'placeholder' => ''
),
)
) );
if ( ! get_option( 'resume_manager_enable_resume_upload' ) )
unset( self::$fields['resume_fields']['resume_file'] );
if ( ! get_option( 'resume_manager_enable_categories' ) || wp_count_terms( 'resume_category' ) == 0 )
unset( self::$fields['resume_fields']['resume_category'] );
if ( ! get_option( 'resume_manager_enable_skills' ) )
unset( self::$fields['resume_fields']['resume_skills'] );
}
Help me out guys! Thanks

Try this code, `$skill1 = $wpdb->get_results("SELECT ID,user_id,Skills FROM wp_candidate_skills WHERE user_id='$id'");
$count = count($skill1);
$array = array();
foreach ($skill1 as $key => $value) {
$sk = $value->Skills;
$array[] = $sk;
}
$fixId =array();
$fixId[0] ='';
for($i=0;$i<=$count-1;$i++)
{
$temp = $array[$i];
$fixId[0] = $fixId[0].$temp.',';
}
$data = $fixId[0] ;
$words = array_filter(preg_split('/\s*,\s*/', $data));
$temp = implode(', ', $words);`
It will fetch data as an array with comma inserted between two values.

Use get_results like below:
<?php
global $wpdb; //important
$result = $wpdb->get_results("SELECT Skills FROM wp_candidate_skills WHERE user_id='$id' ");
foreach($result as $row)
{
echo $row->Skills."<br>";
}
Display mysql table data in a wp page

Use the code like below:
public static function init_fields() {
if ( self::$fields )
return;
global $wpdb;
$current_user = wp_get_current_user();
$user = $current_user->user_login;
$useremail = $current_user->user_email;
$id=$current_user->ID;
$result = $wpdb->get_results("SELECT ID,user_id,Skills FROM wp_candidate_skills WHERE user_id=$id");
print_r($result);
die();
}

Try this way
$current_user = wp_get_current_user();
$id=$current_user->ID;
$skill1 =mysql_query("SELECT Skills FROM wp_candidate_skills WHERE user_id='".$id."' ");
$arr = mysql_fetch_array($skill1);
print_r($arr);

Related

update_post_meta() save custom multicheck box on database but it doesn't show on front end

I have two csv databases, I already migrate de patients database to wordpress but now I need to migrate a services database, each patient can have 1 or more services. First I compare both csv databases and add the data if the Name and Last Name are the same. Everything works good, the data is in the wordpress database because I can print it, but the multicheck box doesn't show the saved data:
And another problem is that I can't click update because on the front end there is no checkbox checked so the custom post type updates the database with nothing checked.
Here is the code that I am using to get the csv data and saves it on the wordpress database:
`function wd_add_data_metabox_with_namemb()
{
wp_suspend_cache_addition(true);
$file_path = get_stylesheet_directory() . '/PATINENTS_LAVISH.csv';
// echo var_dump($file_path);
if (isset($file_path)) {
$filename = $file_path;
$count_patients = 0;
$file = fopen($filename, "r");
while (($getData = fgetcsv($file, null, ',')) !== FALSE) { //GET THE VARIABLES SET
$count_patients++;
echo $count_patients . " :";
echo var_dump($getData);
echo '<br/>';
$name = $getData[2];
$last_name = $getData[3];
if ($name != '') {
$file_path_2 = get_stylesheet_directory() . '/CHARTS_PATIENTS.csv';
$filename_2 = $file_path_2;
$count_charts = 0;
$file_2 = fopen($filename_2, "r");
while (($getData_2 = fgetcsv($file_2, null, ',')) !== FALSE) { //GET THE VARIABLES SET
echo "Chart " . $count_charts . " : ";
echo var_dump($getData_2);
echo '<br/>';
$name_chart = $getData_2[0];
$last_name_chart = $getData_2[1];
echo $name . ' and ' . $name_chart;
echo $last_name . ' and ' . $last_name_chart;
echo '<br/>';
if ($name == $name_chart && $last_name == $last_name_chart) {
$q = new WP_Query(array(
'post_type' => 'patient',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'patient_name',
'value' => $name,
),
array(
'key' => 'patient_last_name',
'value' => $last_name,
),
)
));
while ($q->have_posts()) {
$q->the_post();
$patient_id_chart = get_the_ID();
echo 'Patient ID ' . $patient_id_chart;
$service_chart = get_post_meta($patient_id_chart, 'patient_area_treated_group', true);
$service_chart_2 = get_post_meta($patient_id_chart, 'patient_pre_charting_answers', true);
echo var_dump($service_chart_2);
// check for existing charts
if (!empty($service_chart)) {
$key = count($service_chart);
} else {
$key = 0;
}
if (get_post_type() == 'patient') {
$ticket_id = $patient_id_chart . '-' . $key;
$area_treated = array(
explode(' $', $getData_2[2], 2),
);
$time = strtotime($getData_2[8]);
$comments = $getData_2[6];
$discount_type = 'fixed';
$discount_amount = $getData_2[7];
$chart_energy = $getData_2[4];
$chart_size = $getData_2[3];
$chart_dcd = $getData_2[5];
if (get_page_by_title($area_treated[0], OBJECT, 'service')) {
// Exists
} else {
// Gather post data.
$my_post = array(
'post_title' => $area_treated[0][0],
'post_status' => 'publish',
'post_type' => 'service',
'meta_input' => array(
'service_male_price' => $area_treated[0][1],
'service_female_price' => $area_treated[0][1]
)
);
// Insert the post into the database.
wp_insert_post($my_post);
}
$service_chart[$key] = array(
'patient_service_ticket_id' => $ticket_id,
'patient_area_treated' => $area_treated,
'patient_service_units' => NULL,
'patient_service_time_treated' => $time,
'patient_service_comments' => $comments,
'patient_service_discount_type' => $discount_type,
'patient_service_discount_amount' => $discount_amount,
'patient_service_picture' => NULL,
);
$pre_service_chart[$key] = array(
'patient_service_pre_chart_id' => $ticket_id,
'patient_pregnant' => '',
'patient_pre_chart_comments' => NULL,
'patient_chart_energy' => $chart_energy,
'patient_chart_size' => $chart_size,
'patient_chart_dcd' => $chart_dcd,
);
if (!empty($area_treated) || $comments != '' || $discount_type != '' || $discount_amount != '') {
update_post_meta($patient_id_chart, 'patient_area_treated_group', $service_chart);
}
if (!empty($area_treated)) {
update_post_meta($patient_id_chart, 'patient_pre_charting_answers', $pre_service_chart);
// reset the form
update_post_meta($patient_id_chart, 'patient_area_treated', '');
update_post_meta($patient_id_chart, 'patient_service_time_treated_single', '');
update_post_meta($patient_id_chart, 'patient_service_comments_single', '');
update_post_meta($patient_id_chart, 'patient_service_discount_type_single', '');
update_post_meta($patient_id_chart, 'patient_service_discount_amount_single', '');
update_post_meta($patient_id_chart, 'patient_service_pre_chart_id', '');
update_post_meta($patient_id_chart, 'patient_pregnant', '');
update_post_meta($patient_id_chart, 'patient_pre_chart_comments', '');
update_post_meta($patient_id_chart, 'patient_chart_energy', '');
update_post_meta($patient_id_chart, 'patient_chart_size', '');
update_post_meta($patient_id_chart, 'patient_chart_dcd', '');
}
}
}
$count_charts++;
}
wp_reset_postdata();
}
}
}
fclose($file);
}
}
add_action('wp_head', 'wd_add_data_metabox_with_namemb');`
I just need the multicheckbox to read the database and show the checked options.
This is the code that creates all the custom fields for the patients custom post type with cmb2 plugin:
function patient_meta()
{
$role = user_has_role(get_current_user_id(), 'staff_nurse');
/**
* Metaboxes for Patient Info
*/
if ($role == false) {
$cmb_user = new_cmb2_box(array(
'id' => 'patient_meta',
'title' => __('Patient Data', 'cmb2'),
'object_types' => array('patient'), // Tells CMB2 to use user_meta vs post_meta
'show_names' => true,
'vertical_tabs' => false,
'tabs' => array(
array(
'id' => 'tab-1',
'title' => __('Info', 'cmb2'),
'fields' => array(
'patient_name',
'patient_last_name',
'patient_cell_phone',
'patient_home_phone',
'patient_date_of_birth',
'patient_gender',
'patient_email',
'patient_comments'
),
),
array(
'id' => 'tab-2',
'title' => __('Services', 'cmb2'),
'fields' => array(
'patient_area_treated_single',
'patient_service_comments_single',
'patient_service_discount_type_single',
'patient_service_discount_amount_single',
'patient_service_submit_single',
),
),
array(
'id' => 'tab-3',
'title' => __('Charts', 'cmb2'),
'fields' => array(
'patient_pre_charting_answers',
'patient_pre_chart_comments',
'patient_chart_area_treated',
'patient_time_treated',
'patient_chart_energy',
'patient_chart_size',
'patient_chart_dcd',
'patient_chart_comments',
'patient_chart_discount_type',
'patient_chart_discount_amount',
),
),
array(
'id' => 'tab-4',
'title' => __('Notes', 'cmb2'),
'fields' => array(
'patient_chart_comments',
'patient_note_comments_group',
'patient_notes_comments',
),
),
array(
'id' => 'tab-5',
'title' => __('Images', 'cmb2'),
'fields' => array(
'patient_images',
),
),
array(
'id' => 'tab-6',
'title' => __('Documents', 'cmb2'),
'fields' => array(
'patient_documents',
),
),
array(
'id' => 'tab-7',
'title' => __('Clearances', 'cmb2'),
'fields' => array(
'patient_clearances',
),
),
array(
'id' => 'tab-8',
'title' => __('Referrals', 'cmb2'),
'fields' => array(
'patient_referrals',
'referred_patient_name',
'referred_date',
'referred_date_used',
'referred_discount_used',
'patient_available_ticket_ids',
),
),
array(
'id' => 'tab-9',
'title' => __('History', 'cmb2'),
'fields' => array(
'patient_area_treated_group',
'patient_service_ticket_id',
'patient_area_treated',
'patient_service_comments',
'patient_service_picture',
),
),
),
));
} else {
$cmb_user = new_cmb2_box(array(
'id' => 'patient_meta',
'title' => __('Patient Data', 'cmb2'),
'object_types' => array('patient'), // Tells CMB2 to use user_meta vs post_meta
'show_names' => true,
'vertical_tabs' => false,
'tabs' => array(
array(
'id' => 'tab-1',
'title' => __('Info', 'cmb2'),
'fields' => array(
'patient_name',
'patient_last_name',
'patient_cell_phone',
'patient_home_phone',
'patient_date_of_birth',
'patient_gender',
'patient_email',
'patient_comments'
),
),
array(
'id' => 'tab-2',
'title' => __('Services', 'cmb2'),
'fields' => array(
'patient_area_treated_single',
'patient_service_comments_single',
'patient_service_discount_type_single',
'patient_service_discount_amount_single',
'patient_service_submit_single',
),
),
array(
'id' => 'tab-3',
'title' => __('Charts', 'cmb2'),
'fields' => array(
'patient_pre_charting_answers',
'patient_pre_chart_comments',
'patient_chart_area_treated',
'patient_time_treated',
'patient_chart_energy',
'patient_chart_size',
'patient_chart_dcd',
'patient_chart_comments',
'patient_chart_discount_type',
'patient_chart_discount_amount',
),
),
array(
'id' => 'tab-4',
'title' => __('Notes', 'cmb2'),
'fields' => array(
'patient_chart_comments',
'patient_note_comments_group',
'patient_notes_comments',
),
),
array(
'id' => 'tab-5',
'title' => __('Images', 'cmb2'),
'fields' => array(
'patient_images',
),
),
array(
'id' => 'tab-6',
'title' => __('Documents', 'cmb2'),
'fields' => array(
'patient_documents',
),
),
array(
'id' => 'tab-7',
'title' => __('Clearances', 'cmb2'),
'fields' => array(
'patient_clearances',
),
),
array(
'id' => 'tab-8',
'title' => __('Referrals', 'cmb2'),
'fields' => array(
'patient_referrals',
'referred_patient_name',
'referred_date',
'referred_date_used',
'referred_discount_used',
'patient_available_ticket_ids',
),
),
),
));
}
$cmb_user->add_field(array(
'name' => __('Patient Name', 'cmb2'),
'id' => 'patient_name',
'type' => 'text',
'column' => true,
'description' => '',
));
$cmb_user->add_field(array(
'name' => __('Last Name', 'cmb2'),
'id' => 'patient_last_name',
'type' => 'text',
'column' => true,
));
$cmb_user->add_field(array(
'name' => __('Cell Phone', 'cmb2'),
'id' => 'patient_cell_phone',
'type' => 'text',
'column' => true,
));
$cmb_user->add_field(array(
'name' => __('Home Phone', 'cmb2'),
'id' => 'patient_home_phone',
'type' => 'text',
'column' => true,
));
$cmb_user->add_field(array(
'name' => __('Date of Birth', 'cmb2'),
'description' => '',
'id' => 'patient_date_of_birth',
'type' => 'text_date'
));
$cmb_user->add_field(array(
'name' => 'Gender',
'id' => 'patient_gender',
'type' => 'radio_inline',
'options' => array(
'Male' => __('Male', 'cmb2'),
'Female' => __('Female', 'cmb2')
),
));
$cmb_user->add_field(array(
'name' => __('Email Address', 'cmb2'),
'id' => 'patient_email',
'type' => 'text'
));
$cmb_user->add_field(array(
'name' => __('Patient Comments', 'cmb2'),
'id' => 'patient_comments',
'type' => 'textarea'
));
/**
* Metaboxes for Patient Services
*/
/*****
* Single form to add to history tab
*****/
// $cmb_user->add_field(array(
// 'id' => 'patient_service_ticket_id_single',
// 'type' => 'text',
// 'description' => 'Ticket ID / Chart ID - not for editing',
// 'name' => 'Ticket ID',
// ) );
$cmb_user->add_field(array(
'id' => 'patient_area_treated_single',
'name' => __('Area Treated', 'cmb2'),
'type' => 'radio',
'options' => get_all_services(),
'default' => 'No Treatment $0.00'
));
$cmb_user->add_field(array(
'id' => 'patient_service_time_treated_single',
'name' => __('Time Treated', 'cmb2'),
'type' => 'text_datetime_timestamp',
// 'default' => get_post_datetime()
));
// $cmb_user->add_field(array(
// 'id' => 'patient_service_comments_single',
// 'name' => __('Comments', 'cmb2'),
// 'type' => 'textarea'
// ));
$cmb_user->add_field(array(
'name' => 'Discount Type',
'id' => 'patient_service_discount_type_single',
'type' => 'radio_inline',
'options' => array(
'none' => 'None',
'percentage' => 'Percentage',
'fixed' => 'Fixed Amount'
)
));
$cmb_user->add_field(array(
'name' => __('Discount Amount', 'cmb2'),
'id' => 'patient_service_discount_amount_single',
'type' => 'text'
));
$cmb_user->add_field(array(
'name' => __('Submit Service', 'cmb2'),
'id' => 'patient_service_submit_single',
'type' => 'text'
));
$cmb_user->add_field(array(
'name' => 'Add Service',
'id' => 'patient_service_submit_single',
'type' => 'button',
'after' => '<button value="submit-single" type="submit" class="btn btn-primary">Submit</button>'
));
$group_field_id = $cmb_user->add_field(array(
'id' => 'patient_area_treated_group',
'type' => 'group',
'options' => array(
'group_title' => __('Service {#}', 'cmb2'), // since version 1.1.4, {#} gets replaced by row number
'add_button' => __('Add Another Service', 'cmb2'),
'remove_button' => __('Remove Service', 'cmb2'),
'sortable' => true
),
));
$cmb_user->add_group_field($group_field_id, array(
'id' => 'patient_service_ticket_id',
'type' => 'text',
'description' => 'Ticket ID / Chart ID - not for editing',
'name' => 'Ticket ID'
));
$cmb_user->add_group_field($group_field_id, array(
'id' => 'patient_area_treated',
'name' => __('Area Treated', 'cmb2'),
'type' => 'multicheck',
'options' => get_all_services(),
'default' => 'No Treatment $0.00'
));
$cmb_user->add_group_field($group_field_id, array(
'id' => 'patient_service_time_treated',
'name' => __('Time Treated', 'cmb2'),
'type' => 'text_datetime_timestamp'
));
$cmb_user->add_group_field($group_field_id, array(
'id' => 'patient_service_comments',
'name' => __('Comments', 'cmb2'),
'type' => 'textarea'
));
$cmb_user->add_group_field($group_field_id, array(
'name' => 'Discount Type',
'id' => 'patient_service_discount_type',
'type' => 'radio_inline',
'options' => array(
'none' => 'None',
'percentage' => 'Percentage',
'fixed' => 'Fixed Amount'
)
));
$cmb_user->add_group_field($group_field_id, array(
'name' => 'Discount Amount',
'id' => 'patient_service_discount_amount',
'type' => 'text',
));
// $cmb_user->add_group_field( $group_field_id, array(
// 'id' => 'patient_service_picture',
// 'name' => __('Facial Picture', 'cmb2'),
// 'type' => 'file'
// ));
/**
* Metaboxes for Patient Charting
*/
$group_field_id = $cmb_user->add_field(array(
'id' => 'patient_pre_charting_answers',
'type' => 'group',
'options' => array(
'group_title' => __('Chart {#}', 'cmb2'), // since version 1.1.4, {#} gets replaced by row number
'add_button' => __('Add Another Chart', 'cmb2'),
'remove_button' => __('Remove Chart', 'cmb2'),
'sortable' => true,
),
));
// match pre-chart to service
$cmb_user->add_group_field($group_field_id, array(
'name' => 'This Laser Pre-Chart is for test',
'id' => 'patient_service_pre_chart_id',
'type' => 'select_plus',
'description' => 'Select Service Ticket ID',
'options' => get_ticket_ids()
));
// Id's for group's fields only need to be unique for the group. Prefix is not needed.
$cmb_user->add_group_field($group_field_id, array(
'name' => 'Are you pregnant or breastfeeding?',
'id' => 'patient_pregnant',
'type' => 'radio_inline',
'options' => array(
'Yes' => __('Yes', 'cmb2'),
'No' => __('No', 'cmb2')
),
));
$cmb_user->add_group_field($group_field_id, array(
'name' => 'Pre Chart Comments',
'id' => 'patient_pre_chart_comments',
'type' => 'textarea_small',
));
$cmb_user->add_group_field($group_field_id, array(
'name' => 'Energy',
'id' => 'patient_chart_energy',
'type' => 'text',
));
$cmb_user->add_group_field($group_field_id, array(
'name' => 'Spot Size',
'id' => 'patient_chart_size',
'type' => 'text',
));
$cmb_user->add_group_field($group_field_id, array(
'name' => 'DCD',
'id' => 'patient_chart_dcd',
'type' => 'text',
));
/**
* Metaboxes for Patient Notes
*/
$cmb_user->add_field(array(
'name' => 'Comments',
'id' => 'patient_chart_comments',
'type' => 'textarea_small',
'after' => '<button value="submit-single" type="submit" class="btn btn-primary">Submit</button>',
));
$group_field_id = $cmb_user->add_field(array(
'id' => 'patient_note_comments_group',
'type' => 'group',
'options' => array(
'group_title' => __('Comment {#}', 'cmb2'), // since version 1.1.4, {#} gets replaced by row number
'add_button' => __('Add Another Comment', 'cmb2'),
'remove_button' => __('Remove Comment', 'cmb2'),
'sortable' => true,
),
));
$cmb_user->add_group_field($group_field_id, array(
'name' => 'Comments',
'id' => 'patient_notes_comments',
'type' => 'textarea_small',
));
/**
* Metaboxes for Patient Images
*/
$cmb_user->add_field(array(
'name' => 'Images',
'id' => 'patient_images',
'type' => 'file_list',
'text' => array(
'file_text' => 'test'
)
));
/**
* Metaboxes for Patient Documents
*/
$cmb_user->add_field(array(
'name' => 'Documents',
'id' => 'patient_documents',
'type' => 'file_list',
));
/**
* Metaboxes for Patient Clearances
*/
$cmb_user->add_field(array(
'name' => 'Clearances',
'id' => 'patient_clearances',
'type' => 'file_list',
));
/**
* Metaboxes for Patient Referrals
*/
$group_field_id = $cmb_user->add_field(array(
'id' => 'patient_referrals',
'type' => 'group',
'options' => array(
'group_title' => __('Referral {#}', 'cmb2'), // since version 1.1.4, {#} gets replaced by row number
'add_button' => __('Add Another Referral', 'cmb2'),
'remove_button' => __('Remove Referral', 'cmb2'),
'sortable' => true,
),
));
$cmb_user->add_group_field($group_field_id, array(
'name' => 'Referred Patient Name',
'id' => 'referred_patient_name',
'type' => 'select',
'options' => get_patient_names()
));
$cmb_user->add_group_field($group_field_id, array(
'name' => 'Referred Date',
'id' => 'referred_date',
'type' => 'text_date',
));
$cmb_user->add_group_field($group_field_id, array(
'name' => 'Date Used',
'id' => 'referred_date_used',
'type' => 'text_date',
));
$cmb_user->add_group_field($group_field_id, array(
'name' => 'Discount Used',
'id' => 'referred_discount_used',
'type' => 'radio_inline',
'options' => array(
'Yes' => __('Yes', 'cmb2'),
'No' => __('No', 'cmb2')
),
));
$cmb_user->add_group_field($group_field_id, array(
'id' => 'patient_available_ticket_ids',
'name' => __('Ticket ID', 'cmb2'),
'description' => 'Assign the ticket ID to apply this discount',
'type' => 'select',
'options' => get_ticket_ids()
));
}
add_action('cmb2_init', 'patient_meta');

Updating WooCommerce Admin Shipping Order Fields

In functions.php I am trying to use this, but it is not working:
function rt_woocommerce_admin_shipping_fields( $fields ) {
$fields['first_name']['value'] = $_GET['f'];
$fields['last_name']['value'] = $_GET['l'];
$fields['address_1']['value'] = $_GET['a'];
$fields['address_2']['value'] = $_GET['b'];
// etc
// etc
return $fields;
}
add_filter( 'woocommerce_admin_shipping_fields', 'rt_woocommerce_admin_shipping_fields' );
woocommerce_admin_billing_fields() works but the shipping function does not. Any advice? I need to update the fields with $_GET variables on page load. This works perfectly for the billing fields.
The array has label and show indexes for each item in shipping fields. There is no value index by default. See the woocommerce_admin_shipping_fields filter below.
self::$shipping_fields = apply_filters(
'woocommerce_admin_shipping_fields',
array(
'first_name' => array(
'label' => __( 'First name', 'woocommerce' ),
'show' => false,
),
'last_name' => array(
'label' => __( 'Last name', 'woocommerce' ),
'show' => false,
),
'company' => array(
'label' => __( 'Company', 'woocommerce' ),
'show' => false,
),
'address_1' => array(
'label' => __( 'Address line 1', 'woocommerce' ),
'show' => false,
),
'address_2' => array(
'label' => __( 'Address line 2', 'woocommerce' ),
'show' => false,
),
'city' => array(
'label' => __( 'City', 'woocommerce' ),
'show' => false,
),
'postcode' => array(
'label' => __( 'Postcode / ZIP', 'woocommerce' ),
'show' => false,
),
'country' => array(
'label' => __( 'Country / Region', 'woocommerce' ),
'show' => false,
'type' => 'select',
'class' => 'js_field-country select short',
'options' => array( '' => __( 'Select a country / region…', 'woocommerce' ) ) + WC()->countries->get_shipping_countries(),
),
'state' => array(
'label' => __( 'State / County', 'woocommerce' ),
'class' => 'js_field-state select short',
'show' => false,
),
'phone' => array(
'label' => __( 'Phone', 'woocommerce' ),
),
)
);

How to get values of multiple nested arrays in PHP?

This is a shorter version of my question from How to get values only from a PHP array inside multiple nested Arrays without knowing value? so hoping someone can help.
MAIN ISSUE I don't know what to call to get things inside ARRAY
What I need is inside that Array of Extras. I've duplicated & modified everything I can to get these values but can't seem to figure it out. Any help is really appreciated.
The registration, milage, condition shown is the output of $autoshowroom_portfolio_specifications_arr
array (
'label' => __( 'Checkboxes field', 'progression-car-dealer' ),
'name' => 'pcd_checkboxes',
'display' => 'table',
'min' => '',
'max' => '',
'sub_fields' => array (
array (
'key' => 'field_52816dc9ffee11',
'label' => __( 'Checkboxes to Customize', 'progression-car-dealer' ),
'name' => 'pcd_checkboxes',
'type' => 'checkbox',
'instructions' => __( 'Selected fields will be used', 'progression-car-dealer' ),
'choices' => $choices,
'default_value' => '',
'layout' => 'horizontal',
)
),
),
More code
array(
'id' => 'autoshowroom_Detail_show_extras',
'label' => esc_html__('Show Extras', 'autoshowroom'),
'desc' => '',
'sdt' => 'yes',
'type' => 'select',
'section' => 'TZVehicleDetail',
// 'section' => 'TZVehicle',
'choices' => array(
array(
'value' => 'yes',
'label' => esc_html__('Show', 'autoshowroom'),
),
array(
'value' => 'no',
'label' => esc_html__('Hide', 'autoshowroom'),
)
)
),
$car_extras = array_unique( array_merge( array (
__( 'Auxiliary heating', 'progression-car-dealer' ),
__( 'ABS', 'progression-car-dealer' ),
__( 'Central locking', 'progression-car-dealer' ),
__( 'Power Assisted Steering', 'progression-car-dealer' ),
__( 'Cruise control', 'progression-car-dealer' ),
__( 'Immobilizer', 'progression-car-dealer' ),
__( 'Warranty', 'progression-car-dealer' ),
__( 'Electric windows', 'progression-car-dealer' ),
__( 'Financing', 'progression-car-dealer' ),
__( 'Another', 'progression-car-dealer' ),
__( 'Last', 'progression-car-dealer' ),
), $this->get_meta_values( 'extras', 'vehicle' ) ));
$car_extras = array_combine( $car_extras, $car_extras);
More code
public function register_field( $args ) {
// ACF requires a unique key per field so lets generate one
$key = md5( serialize( $args ));
if ( empty( $args['type'] )) {
$args['type'] = 'number';
}
$type = $args['type'];
if ( 'taxonomy' == $type ) {
$field = wp_parse_args( $args, array(
'key' => $key,
'label' => '',
'name' => '',
'type' => 'taxonomy',
'instructions' => '',
'taxonomy' => '',
'field_type' => 'select',
'allow_null' => 1,
'load_save_terms' => 1,
'return_format' => 'id',
'multiple' => 0,
'sort' => 0,
'group' => 'overview'
) );
} else if ( 'radio' == $type ) {
$field = wp_parse_args( $args, array (
'key' => $key,
'label' => '',
'name' => '',
'instructions' => '',
'choices' => array(),
'other_choice' => 1,
'save_other_choice' => 1,
'default_value' => '',
'layout' => 'horizontal',
'sort' => 0,
'group' => 'specs'
) );
} else if ( 'checkbox' == $type ) {
$field = wp_parse_args( $args, array (
'key' => $key,
'label' => '',
'name' => '',
'instructions' => '',
'choices' => array(),
'layout' => 'vertical',
'sort' => 0,
'multiple' => 1,
'group' => 'specs'
) );
} else {
$field = wp_parse_args( $args, array (
'key' => $key,
'label' => '',
'name' => '',
'type' => 'number',
'instructions' => '',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'min' => 0,
'max' => '',
'step' => '',
'sort' => 0,
'group' => 'specs'
) );
}
$field = apply_filters( 'pcd/register_field', $field );
$this->fields[$field['name']] = $field;
More code
'extras' => array(
'label' => __( 'Extras', 'progression-car-dealer' ),
'name' => 'extras',
'type' => 'checkbox',
'choices' => $car_extras,
'other_choice' => 55,
'save_other_choice' => 55,
'default_value' => '',
'layout' => 'horizontal',
'sort' => 95,
),

How to set Default value on search form?

I'm using a wordpress real estate plugin for my project which is wpcasa, I already do some modification, But this thing takes my time to figure out.
I think they use array to get set values/labels on search form.
Anyone can Help me to how to add default value into a search form?
Here's the code below
$defaults = array(
'keyword' => array(
'label' => __( 'Keyword or Listing ID', 'wpcasa' ) . '…',
'type' => 'text',
'class' => 'width-3-4',
'priority' => 10
),
'submit' => array(
'label' => __( 'Search', 'wpcasa' ),
'type' => 'submit',
'class' => 'width-1-4',
'priority' => 20
),
'offer' => array(
'label' => __( 'Offer', 'wpcasa' ),
'key' => '_price_offer',
'data' => wpsight_offers(),
'type' => 'select',
'data_compare' => '=',
'class' => 'width-1-5',
'priority' => 30
),
'location' => array(
'data' => array(
// wp_dropdown_categories() options
'taxonomy' => 'location',
'show_option_none' => __( 'Location', 'wpcasa' ),
'option_none_value' => '',
'hierarchical' => 1,
'orderby' => 'ID',
'order' => 'ASC'
),
'type' => 'taxonomy_select',
'class' => 'width-1-5',
'priority' => 40
),
'listing-type' => array(
'data' => array(
// wp_dropdown_categories() options
'taxonomy' => 'listing-type',
'show_option_none' => __( 'Type', 'wpcasa' ),
'option_none_value' => '',
'hierarchical' => 1,
'orderby' => 'ID',
'order' => 'ASC'
),
'type' => 'taxonomy_select',
'class' => 'width-1-5',
'priority' => 50
),
$details['details_1']['id'] => array(
'label' => $details['details_1']['label'],
'key' => '_details_1',
'data' => $details['details_1']['data'],
'type' => 'select',
'data_compare' => '>=',
'class' => 'width-1-5',
'priority' => 60
),
$details['details_2']['id'] => array(
'label' => $details['details_2']['label'],
'key' => '_details_2',
'data' => $details['details_2']['data'],
'type' => 'select',
'data_compare' => '>=',
'class' => 'width-1-5',
'priority' => 70
)
);
`
Example on keyword I will set a value HOME Instead showing its label.
Thank you!
I got it now I should add 'default' => 'Myvalue',
example
'keyword' => array(
'label' => __( 'Keyword or Listing ID', 'wpcasa' ) . '…',
'type' => 'text',
'class' => 'width-3-4',
'default' => 'HELLO',
'priority' => 10
),
Thanks for the help/advice!

How to Save the Repeatable fields data in Reusable Custom box WordPress?

hello I am using reusable custom metaboxes from https://github.com/tammyhart/Reusable-Custom-WordPress-Meta-Boxes..
these are my fields
array(
'label' => __('Setup Slider', 'crispy' ),
'desc' => __('create your slider image/ text using these repeatable options', 'crispy' ),
'id' => $prefix.'repeatable',
'type' => 'repeatable',
'sanitizer' => array(
'title' => 'sanitize_text_field',
'desc' => 'wp_kses_data'
),
'repeatable_fields' => array (
array(
'label' => __(' Slider Text alignment', 'crispy'),
'id' => 'alignment',
'type' => 'radio',
'options' => array (
'one' => array (
'label' => __('Left', 'crispy' ),
'value' => 'left'
),
'two' => array (
'label' => __('Center', 'crispy' ),
'value' => 'center'
),
'three' => array (
'label' => __('Right', 'crispy' ),
'value' => 'right'
)
)
),
array(
'label' => __('Background Image/pattern', 'crispy' ),
'id' => 'image',
'type' => 'image'
),
array(
'label' => __('Title', 'crispy' ),
'id' => 'title',
'type' => 'text'
),
array(
'label' => __('Description', 'crispy' ),
'id' => 'desc',
'type' => 'textarea'
),
)
),
My problem is i don't know how to store the fields value... can anyone resolve my problem!!..
$home_slider_alignment = get_post_meta( $post->ID, 'alignment', true);
i used this but doesn't help!!.. Those fields can be repeatable so the values are stored in array!!.. i don't know how to retrieve stored values from that array??..
Please help me!!.
It is working :)
enter code here
<?php
$projectgallery = get_post_meta($post->ID, 'arcadia_well_projectgallery', true); {
echo '<ul class="custom_repeatable">';
foreach ($projectgallery as $project) {
echo '<li>';
foreach($project as $i=>$value) {
echo $value;
}
echo '</li>';
}
echo '</ul>';
}
?>

Categories