Quantcast
Channel: Toolset » All Posts
Viewing all articles
Browse latest Browse all 20145

SCRIPT TO ADD CHECKBOXSES FROM PHP TABLE

$
0
0

hey,
i need help with a script that i have wrote.

this function belongs to function.php on my child theme:

if (!function_exists('wpcf_add_checkboxes_to_group')) {

function wpcf_add_checkboxes_to_group()
{
global $wpdb;

$field_name = "available countries";
$field_slug = "available-countries";

$table_name = "countrycodes";
$key = "code";
$value = "country";

$rows = $wpdb->get_results("SELECT country,code
FROM $table_name
WHERE $key != '' and $value != ''", ARRAY_N);

$countries = array('name' => $field_name,
'slug' => $field_slug,
'description' => '',
'save_empty' => 'no'
);

foreach ($rows as $row) {
$option_slug = $row[0];
$option_value = $row[1];
$option_key = wpcf_unique_id(com_create_guid());
$options['wpcf-fields-checkboxes-option-' . $option_key] = array('title' => $option_slug,
'set_value' => $option_value,
'display' => 'value',
'display_value_not_selected' => 0,
'display_value_selected' => $option_value);
}
$countries['options'] = $options;
$countries['type'] = 'checkboxes';
$countries['conditional_display'] = array('relation' => 'AND',
'custom' => '');

$_POST['wpcf']['fields'][$field_name] = $countries;

}
add_action( 'wpcf_save_admin_group', 'wpcf_add_checkboxes_to_group' );
}

and i have added:
// hook to wpcf_save_admin_group in wp-content\plugins\types\includes\field-form.php line 122
// do_action( 'wpcf_save_admin_group', $_POST['wpcf']['group'] );

now all you need is to go to


Viewing all articles
Browse latest Browse all 20145

Trending Articles