So, I've got the following code:
function themename_customize_register($wp_customize){
// Display date
$wp_customize->add_section('display_date_section', array(
'title' => 'Datum weergeven',
'description' => 'Wil je de datum weergeven?',
'priority' => 120,
));
$wp_customize->add_setting('display_date', array(
'default' => 'value1',
'capability' => 'edit_theme_options',
'type' => 'option',
));
$wp_customize->add_control('display_date_section', array(
'label' => 'Datum weergeven:',
'section' => 'display_date_section',
'settings' => 'display_date',
'type' => 'theme_mod',
'choices' => array(
'value1' => 'Ja',
'value2' => 'Nee',
),
));
}
add_action('customize_register', 'themename_customize_register');
How can I access the value of the setting? Right now whenever I try to access it (either through get_theme_mod or $wp_customize->get_settings) My main goal with the code is to let users have the ability to control wether they want to display the date or not. Can somebody help me? :D
Related
I have a form with a multiple select field where a user can select several values in it
$form['export_type_section']['export_type'] = array(
'#title' => t('Export types'),
'#type' => 'select',
'#multiple' => TRUE,
'#size' => 10,
'#options' => $options,
'#ajax' => array(
'event' => 'change',
'callback' => 'test_export_form_export_type_ajax_callback',
),
);
I have another field in the form
$form['document_type'] = array(
'#type' => 'select',
'#options' => array(0 => t('All Types'), 1 => t('Test1'), 2 => t('Test2'), 3 => t('Test3')),
'#title' => 'Document Types',
'#default' => 0,
'#ajax' => array(
'event' => 'change',
'callback' => 'test_export_form_document_type_ajax_callback',
),
);
I am trying to figure out how to reset the export_type field when the document_type is changed. I would like to clear the selected values so that the user can reselect what is needed whenever the document_type changes. I tried several formats in the test_export_form_document_type_ajax_callback but none worked.
Anybody knows how to do it?
i'm trying to add a tab to my wordpress customizer.
i use the next code:
add_action('customize_register','theme_costumizer_register');
function theme_costumizer_register($wp_customize){
$wp_customize->add_section('facebook_new_section', array(
'title' => 'Social Media',
'priority' => 10
));
$wp_customize->add_settings('facebook',
array(
'default' => 'http://facebook.com/ahiad'
));
$wp_customize->add_control(new WP_Customize_Control($wp_customize,'txtFacebookAddress',
array(
'label' => 'Facebook Link',
'section' => 'facebook_new_section',
'type' => 'text'
)));
}
the problem is every time i run this piece of code in my website, i get an error 500, could not spot the problem here...
You are using $wp_customize->settings which is not not exists, Please use $wp_customize->setting.
Please try below code :
add_action('customize_register','theme_costumizer_register');
function theme_costumizer_register($wp_customize){
$wp_customize->add_section('facebook_new_section', array(
'title' => 'Social Media',
'priority' => 10
));
$wp_customize->add_setting('facebook',
array(
'type' => 'theme_mod', // or 'option'
'capability' => 'edit_theme_options',
'theme_supports' => '', // Rarely needed.
'default' => 'http://facebook.com/ahiad',
'transport' => 'refresh', // or postMessage
'sanitize_callback' => '',
'sanitize_js_callback' => '',
));
$wp_customize->add_control('facebook',
array(
'label' => 'Facebook Link',
'section' => 'facebook_new_section',
'type' => 'text'
));
}
I hope it will helps you. Thanks
I'm using CMB to creat custom fields for wordpress custom post
https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress
I'm using text_datetime_timestamp to set date and time and I need to make this field repeatable which is not
as I go through the documentation we can make new fields but I can't figure out how it make "text_datetime_timestamp" field repeatable
any body can show me the way to accomplish that ?
thank you
I did not find a solution to make the field repeatable so I put the field inside group and made it repeatable
array(
'id' => $prefix . 'repeat_date_group',
'type' => 'group',
'description' => '',
'options' => array(
'group_title' => __( 'Date/Time {#}', 'cmb' ),
'add_button' => __( 'Add Another Date/Time', 'cmb' ),
'remove_button' => __( 'Remove Date/Time', 'cmb' ),
'sortable' => true, // beta
),
'fields' => array(
array(
'name' => 'Date/Time',
'desc' => '',
'id' => $prefix . 'course_date',
'type' => 'text_datetime_timestamp'
),
),
),
I hope this answer will help somebody
Well here is my code, you may try this
$cmb= new_cmb2_box( array(
'id' => $prefix.'testing',
'title' => _('Testing'),
'object_types' => array('post'),
'context' => 'normal',
'priority' => 'high',
'show_names' => true,
));
$cmb->add_field( array(
'name' => 'Test Date/Time Picker Combo (UNIX timestamp)',
'id' => 'wiki_test_datetime_timestamp',
'type' => 'text_datetime_timestamp',
'repeatable' => true,
) );
I was wondering if i can create programmatically a CCK field instance and insert the "allowed_values" in a single stage. So i tried this:
field_create_instance(array(
'field_name' => 'card number',
'entity_type' => 'payment_method',
'bundle' => 'debit_card',
'label' => t('Debit/Credit card'),
'description' => t('Add card\'s number '),
'widget' => array(
'type' => 'options_select',
'weight' => 0,
'settings' => array('size' => 50),
),
'required' => TRUE,
));
I've tried some case i.e to set in 'setting' => array( 'allowed_values' => array( 1, 2, 3 ) ) but nothing happened. Any suggestions?
Solution:
function MY_MODULE_install() {
field_create_field(array(
'field_name' => 'months',
'type' => 'list_text',
'cardinality' => 1,
'settings' => array('allowed_values_function' => 'get_months'),
'entity_types' => array('user', 'node'),
));
}
function get_months() {
$months = array( '01', '02', '03',...'12');
return $months;
}
Warning: Callback function must always be in *.module file of your custom module.
So, I have serialized data within the uc_orders table. This data has several parameters of interest each of which I want to create a unique field from.
Each one of these $data values work on their own. Obviously I am rewriting the value on the second declaration. How can I reference the same data location twice so that both of the fields can be used and I can explode all of my serialized data into separate fields?
function uc_order_views_data() {
$data['uc_orders']['data'] = array(
'group' => t('Order') . ':data',
'title' => t('Arrival Date'),
'help' => t('Arrival date choosen by customer during checkout.'),
'field' => array(
'handler' =>'uc_order_handler_field_arrive_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
$data['uc_orders']['data'] = array(
'group' => t('Order') . ':data',
'title' => t('Ship Date'),
'help' => t('The date to ship the order by.'),
'field' => array(
'handler' =>'uc_order_handler_field_ship_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
}
I finally found the answer.
$data['uc_orders']['data2'] = array(
'group' => t('Order') . ':data',
'title' => t('Arrival Date'),
'real field' => 'data',
'help' => t('Arrival date choosen by customer during checkout.'),
'field' => array(
'handler' =>'uc_order_handler_field_arrive_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
$data['uc_orders']['data'] = array(
'group' => t('Order') . ':data',
'title' => t('Ship Date'),
'help' => t('The date to ship the order.'),
'field' => array(
'handler' =>'uc_order_handler_field_ship_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
The solution is to add 'real field' => 'field name', and change the $data id.