WordPress taxonomy checkboxes - php

I have a metabox in my post editor which allows me to pick a single category, I would like this changed to a checkbox where more than one can be picked. I have worked on the following, I would imagine it's a case of changing taxonomy_radio to something like taxonomy_checkbox, however that crashes the metabox completely:
$meta_boxes['test_metabox'] = array(
'id' => 'test_metabox',
'title' => __( 'TEST', 'cmb' ),
'pages' => array( 'post', ),
'context' => 'normal',
'priority' => 'high',
'show_names' => true,
'fields' => array(
array(
'name' => __( 'Category', 'cmb' ),
'desc' => __( 'field description (optional)', 'cmb' ),
'id' => 'test-cat',
'type' => 'taxonomy_radio',
'taxonomy' => 'category'
),
Any help would be great.

Just found out that it needs to be changed to taxonomy_multicheck

Related

Adding Row settings to WPBakery plugin

How do I get the settings to the frontend? I need to add classes to vc_row.
/**
* Ken Burns Effect for Row.
*/
add_action( 'vc_after_init', 'ken_burns_effect_add_option_to_vc_row' );
function ken_burns_effect_add_option_to_vc_row() {
// Ken Burns Effect Attributes
$ken_burns_effect_attributes =
array(
array(
'type' => 'checkbox',
'heading' => __( 'Ken Burns for image background', 'ken_burns_effect' ),
'param_name' => 'enable_ken_burns_effect',
'value' => array(
__( 'Yes', 'ken_burns_effect' ) => 'yes',
),
'description' => 'Check this box if you want to enable ken burns effect for this row.',
),
array(
'type' => 'dropdown',
'heading' => __( 'Direction', 'ken_burns_effect' ),
'param_name' => 'direction_ken_burns_effect',
'value' => array(
'Zoom In' => 'zoom_in',
'Zoom Out' => 'zoom_out',
),
'description' => __( '', 'ken_burns_effect' ),
'dependency' => array(
'element' => 'enable_ken_burns_effect',
'value' => array( 'yes' ),
),
),
array(
'type' => 'textfield',
'heading' => __( 'Transition speed', 'ken_burns_effect' ),
'param_name' => 'transition_speed_ken_burns_effect',
'value' => '',
'description' => __( '', 'ken_burns_effect' ),
'dependency' => array(
'element' => 'enable_ken_burns_effect',
'value' => array( 'yes' ),
),
),
);
vc_add_params( 'vc_row', $ken_burns_effect_attributes);
}
You will have to override the vc_row.php by copying it to your theme or plugin.
You can check their documentation on how to set the override directory: https://kb.wpbakery.com/docs/inner-api/vc_set_shortcodes_templates_dir/
Then you can use your custom params inside vc_row.php using their param_name eg:
$enable_ken_burns_effect;
$direction_ken_burns_effect;
$transition_speed_ken_burns_effect;
Keep in mind that you have to override vc_row_inner.php too if you want to use options there. Same goes for section and columns.

Adding fields to an options page

I'm trying to add fields to an options page through PHP, and I can't get it to work, I've tried nearly everything by now, but it just won't work.
I hope you can help, my php looks like this:
if (function_exists('acf_add_options_page')) {
$option_page = acf_add_options_page(array(
'page_title' => 'Indstillinger',
'menu_title' => 'Indstillinger',
'menu_slug' => 'options',
'capability' => 'edit_posts',
'redirect' => false
));
}
function my_acf_add_local_field_groups() {
acf_add_local_field_group(array(
'key' => 'group_1',
'title' => 'My Group',
'fields' => array(
array(
'key' => 'field_1',
'label' => 'Sub Title',
'name' => 'sub_title',
'type' => 'text',
)
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'options',
),
),
),
));
}
add_action('acf/init', 'my_acf_add_local_field_groups');
What am I doing wrong here?
I have found out.
'location' => array(
array(
array(
'param' => 'options_page',
'operator' => '==',
'value' => 'theme-general-settings',
),
),
),
Here in the value field just add the "menu slug" that you have registered for the options page. Like 'theme-header-settings', 'theme-general-settings' are you requirement. I hope you understand.
I think you want
'location' => array(
array(
array(
'param' => 'options_page',
'operator' => '==',
'value' => 'options',
),
),
),
The way you have added Option page, it seems that you have installed ACF plugin.
You can add any type of field on your option page using ACF plugin as well.
Check my attached screen shot, You need to set following condition for the field groups:

wordpress redux framework - create a repeater field and show values later

I am trying to use Redux inside the wordpress theme and not as a plugin. In functions.php I included both redux-framework.php and sample-config.php .
Now I need to create a repeater field.
From Redux doc, I got the following code to use in order to create a repeater field:
$this->sections[] = array(
'title' => __('Repeater Field', 'redux-framework-demo' ),
'icon' => 'el-icon-thumbs-up',
'fields' => array(
array(
'id' => 'repeater-field-id',
'type' => 'repeater',
'title' => __( 'Title', 'redux-framework-demo' ),
'subtitle' => __( '', 'redux-framework-demo' ),
'desc' => __( '', 'redux-framework-demo' ),
//'group_values' => true, // Group all fields below within the repeater ID
//'item_name' => '', // Add a repeater block name to the Add and Delete buttons
//'bind_title' => '', // Bind the repeater block title to this field ID
//'static' => 2, // Set the number of repeater blocks to be output
//'limit' => 2, // Limit the number of repeater blocks a user can create
//'sortable' => false, // Allow the users to sort the repeater blocks or not
'fields' => array(
array(
'id' => 'title_field',
'type' => 'text',
'placeholder' => __( 'Title', 'redux-framework-demo' ),
),
array(
'id' => 'text_field',
'type' => 'text',
'placeholder' => __( 'Text Field', 'redux-framework-demo' ),
),
array(
'id' => 'select_field',
'type' => 'select',
'title' => __( 'Select Field', 'redux-framework-demo' ),
'options' => array(
'1' => __( 'Option 1', 'redux-framework-demo' ),
'2' => __( 'Option 2', 'redux-framework-demo' ),
'3' => __( 'Option 3', 'redux-framework-demo' ),
),
'placeholder' => __( 'Listing Field', 'redux-framework-demo' ),
),
)
)
)
);
but if I place the code inside functions.php, what will the $this variable refer to? It'll produce errors. So how to use the snippet so that I can retrieve the values from template files as well?
You have to tried an old version system to create a section. You can try the new version system, I'm not sure if this works or not, but you can try this way:
Redux::setSection($opt_name, array(
'title' => __('Ads Sections', 'cbnews'),
'id' => 'ads-sections',
'desc' => __('You can manage your ads', 'cbnews'),
'icon' => 'dashicons dashicons-dashboard',
'fields' => array(
array(
'id' => 'repeater-field-id',
'type' => 'repeater',
'title' => __( 'Title', 'redux-framework-demo' ),
'subtitle' => __( '', 'redux-framework-demo' ),
'desc' => __( '', 'redux-framework-demo' ),
//'group_values' => true, // Group all fields below within the repeater ID
//'item_name' => '', // Add a repeater block name to the Add and Delete buttons
//'bind_title' => '', // Bind the repeater block title to this field ID
//'static' => 2, // Set the number of repeater blocks to be output
//'limit' => 2, // Limit the number of repeater blocks a user can create
//'sortable' => false, // Allow the users to sort the repeater blocks or not
'fields' => array(
array(
'id' => 'title_field',
'type' => 'text',
'placeholder' => __( 'Title', 'redux-framework-demo' ),
),
array(
'id' => 'text_field',
'type' => 'text',
'placeholder' => __( 'Text Field', 'redux-framework-demo' ),
),
array(
'id' => 'select_field',
'type' => 'select',
'title' => __( 'Select Field', 'redux-framework-demo' ),
'options' => array(
'1' => __( 'Option 1', 'redux-framework-demo' ),
'2' => __( 'Option 2', 'redux-framework-demo' ),
'3' => __( 'Option 3', 'redux-framework-demo' ),
),
'placeholder' => __( 'Listing Field', 'redux-framework-demo' ),
),
)
)
)
));

Displaying the latest posts from a custom field group

i have this custom Metabox field group from https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/wiki/Field-Types#group containing 3 fields and displayed on the Products page template, i want to call the latest posts the client add to display them on my front-page. here is the code of the custom fields.
/**
* Repeatable Field Groups
*/
$meta_boxes['field_group'] = array(
'id' => 'field_group',
'title' => __( 'Manage your products here', 'cmb2' ),
'show_on' => array( 'id' => array( 11, ) ), // Specific post IDs to display this metabox
'object_types' => array( 'page', ),
'fields' => array(
array(
'id' => $prefix . 'repeat_group',
'type' => 'group',
'options' => array(
'group_title' => __( 'Product {#}', 'cmb2' ), // {#} gets replaced by row number
'add_button' => __( 'Add Another Product', 'cmb2' ),
'remove_button' => __( 'Remove Product', 'cmb2' ),
'sortable' => true, // beta
),
'fields' => array(
array(
'name' => 'Product Name',
'id' => 'product_name',
'type' => 'text',
),
array(
'name' => 'Product Description',
'description' => 'Write a short description for this Product',
'id' => 'product_description',
'type' => 'textarea',
),
array(
'name' => 'Product Image',
'id' => 'product_image',
'type' => 'file',
),
),
),
),
);
UPDATE:
i found this http://codex.wordpress.org/Function_Reference/wp_get_recent_posts but i still can't figure out how to make it get the posts from the custom fields

select box in wordpress for meta field

I am registering a post in my wp-admin but I don't want editor etc, so adding some field. By the R & D I founded how to add text box and it's awesome but now I have to add a select box and the option value should be post title. I don't want to do this by plugin.
I added text field as:
$client_meta_box = array(
'id' => 'meta-client',
'title' => __('Client Options','mfn-opts'),
'page' => 'client',
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'id' => 'post-link',
'type' => 'text',
'title' => __('Link', 'opts'),
'sub_desc' => __('Link to client`s site', 'opts'),
),
),
);
and I can add select box by just change the type as 'type' => 'select' but how did I get the post title value in option.
Using this to add meta box lile text, chackbox, selectoption.
$meta_boxes[] = array(
'id' => 'meta-client', // meta box id, unique per meta box
'title' => 'Client Options', // meta box title
'pages' => array('client'), // post types, accept custom post types as well,
//default is array('post'); optional
'priority' => 'high', // order of meta box: high (default), low; optional
'fields' => array(
array(
'label'=> 'Text Input',
'desc' => 'A description for the field.',
'id' => $prefix.'text',
'type' => 'text'
),
array(
'label'=> 'Textarea',
'desc' => 'A description for the field.',
'id' => $prefix.'textarea',
'type' => 'textarea'
),
array(
'label'=> 'Checkbox Input',
'desc' => 'A description for the field.',
'id' => $prefix.'checkbox',
'type' => 'checkbox'
),
array(
'label'=> 'Select Box',
'desc' => 'A description for the field.',
'id' => $prefix.'select',
'type' => 'select',
'options' => array(
'option1' => 'Optionone', // 'value'=>'label'
'option2' => 'Optiontwo',
'option3' => 'Optionthree'
)
)
);

Categories