I have implemented the CMB2/cmb2-attached-post library in my wordpress installation and created a custom post type in which to use it.
I have implemented the example described in the example-field-setup-php, specifically, in this way:
$example_meta = new_cmb2_box( array(
'id' => 'cmb2_attached_posts_field',
'title' => __( 'Attached Posts', 'yourtextdomain' ),
'object_types' => array( 'luogo' ), // Post type
'context' => 'normal',
'priority' => 'high',
'show_names' => true, // Show field names on the left
) );
$example_meta->add_field( array(
'name' => __( 'Attached Posts', 'yourtextdomain' ),
'desc' => __( 'Drag ...', 'yourtextdomain' ),
'id' => 'attached_cmb2_attached_posts',
'type' => 'custom_attached_posts',
'column' => true,
'options' => array(
'show_thumbnails' => true,
'filter_boxes' => true,
'query_args' => array(
'posts_per_page' => 10,
'post_type' => 'page',
),
),
) );
$example_meta->add_field( array(
'name' => __( 'Attached Users', 'yourtextdomain' ),
'desc' => __( 'Drag ...', 'yourtextdomain' ),
'id' => 'attached_cmb2_attached_users',
'type' => 'custom_attached_posts',
'column' => true,
'options' => array(
'show_thumbnails' => true,
'filter_boxes' => true,
'query_users' => true,
),
) );
The result I get graphically is this:
Which is visibly broken and malfunctioning.
What I got as a result is the following: (as shown on the library repo).
Why do I get a broken result if the library has been integrated as per the documentation?
Is something missing?
What I have done for use is:
Installing the library with composer and the inclusion of the library in the .php file where I create the custom post type:
require_once ( get_template_directory() . /vendor/webdevstudios/cmb2-attached-posts/init.php' );
Related
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.
I am using wordpress and 2 plugins called unyson and brizy.
Basically unyson provides me a shortcode I want to call trough the front page builder brizy on my homepage.
I want to call the portfolio shortcode with [portfolio]
This works.
Live website: https://xprs.ch/
Under "Our Work Portfolio"
Now I want to add options:
[portfolio page_link="On" categories="website"]
As long as I just define page_link it works.
But as soon as I try to define the categories I get the following error:
Warning: in_array() expects parameter 2 to be array, string given in /home/httpd/vhosts/xprs.ch/httpdocs/wp-content/themes/jevelin/framework-customizations/extensions/shortcodes/shortcodes/portfolio/views/view.php on line 100
I also get above error if just defining categories so I need to define this different but how?
The code from the shortcode:
NOTE: I cannot change this code.
I need to pass the parameter "website" correctly in the front end.
$options = array(
'id' => array( 'type' => 'unique' ),
'general' => array(
'title' => esc_html__( 'General', 'jevelin' ),
'type' => 'tab',
'options' => array(
'style' => array(
'type' => 'radio',
'label' => esc_html__('Style', 'jevelin'),
'desc' => esc_html__('Choose main style', 'jevelin'),
'choices' => array(
'default' => esc_html__('Standard', 'jevelin'),
'default-shadow' => esc_html__('Standard with Shadow', 'jevelin'),
'default2' => esc_html__('Trendy', 'jevelin'),
'masonry' => esc_html__('Gallery', 'jevelin'),
'masonry2' => esc_html__('Marginless Gallery', 'jevelin'),
'minimalistic' => esc_html__('Minimalistic', 'jevelin'),
),
'value' => 'default',
),
'categories' => array(
'type' => 'multi-select',
'label' => esc_html__('Categories', 'jevelin'),
'desc' => esc_html__('Select categories', 'jevelin'),
'population' => 'taxonomy',
'source' => 'fw-portfolio-category',
'prepopulate' => 200,
'limit' => 100,
),
'page_link' => array(
'type' => 'switch',
'label' => esc_html__( 'Page Link', 'jevelin' ),
'desc' => esc_html__( 'Enable or disable portfolio page link', 'jevelin' ),
'value' => true,
'left-choice' => array(
'value' => false,
'label' => esc_html__('Off', 'jevelin'),
),
'right-choice' => array(
'value' => true,
'label' => esc_html__('On', 'jevelin'),
),
),
),
),
);
How do I need to call categories?
Here:
$cats = array();
foreach( get_the_category() as $cat ) {
$cats[] = $cat->cat_ID;
}
$args = array(
'post_status' => 'publish',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => $cats,
'include_children' => false
)
)
);
print_r( WP_Query( $args ) as $post );
http://codex.wordpress.org/Class_Reference/WP_Query
I try to make the transfer of a WordPress theme options from SMOF to the Redux Framework since SMOF is no longer maintained. I have successfully transferred all other options and they work perfectly but I have trouble in following context, getting this error:
Parse error: syntax error, unexpected 'foreach' (T_FOREACH), expecting ')'
The old code was used to create a built-in translator option using "type" => "text", and has works great but no I do not know how to implement it in the new Redux Framework to run and no longer occur this error.
Here's the old code from the SMOF Framework:
$translate_strings = theme_get_translate_options();
foreach ( $translate_strings as $string_key => $string ) {
$of_options[] = array( "name" => esc_html( $string['string_text'] ),
"id" => 'td_'.$string_key,
"type" => "text",
);
}
And here is the new interface of Redux Framework. where are supposed to implement the old code using : "type" => "text", :
$translate_strings = theme_get_translate_options();
// -> START Translation Info Fields
Redux::setSection( $opt_name, array(
'title' => __( 'Translator', 'redux-framework-demo' ),
'desc' => __( '', 'redux-framework-demo' ),
'id' => 'translator-info-subsection',
'subsection' => true,
'fields' => array(
array(
'id' => '',
'type' => 'text',
'title' => __( '', 'redux-framework-demo' ),
'desc' => __( '', 'redux-framework-demo' ),
),
)
) );
The code that I used and makes the errors occurs is the following:
$translate_strings = theme_get_translate_options();
Redux::setSection( $opt_name, array(
'title' => __( 'Translator', 'redux-framework-demo' ),
'desc' => __( '', 'redux-framework-demo' ),
'id' => 'translator-info-subsection',
'subsection' => true,
'fields' => array(
foreach ( $translate_strings as $string_key => $string ) {
array(
'id' => 'td_'.$string_key,
'type' => 'text',
'title' => __( '', 'redux-framework-demo' ),
),
}
)
) );
I'm completely stuck on this and any help or suggestion will be greatly appreciated.
Thank you!
A little reorganization should be enough:
$translate_strings = theme_get_translate_options();
$myFields = array();
foreach ( $translate_strings as $string_key => $string ) {
$myFields[]=
array(
'id' => 'td_'.$string_key,
'type' => 'text',
'title' => __( '', 'redux-framework-demo' ),
);
}
Redux::setSection( $opt_name, array(
'title' => __( 'Translator', 'redux-framework-demo' ),
'desc' => __( '', 'redux-framework-demo' ),
'id' => 'translator-info-subsection',
'subsection' => true,
'fields' => $myFields
) );
I took out your foreach from the initialization and initialized the array separately.
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
I need a Webinar in my wordpress site. So I'm registering an meta box for my custom post type. I can see my custom post in the wordpress admin panel, but inside the custom post meta box is missing. What is wrong here!
// Meta boxes
add_filter( 'rwmb_meta_boxes', 'navbig_webinars_register_meta_boxes' );
//Register meta boxes
function navbig_webinars_register_meta_boxes( $meta_boxes )
{
$prefix = 'navbig_webinars_';
$meta_boxes[] = array(
'id' => 'standard',
'title' => __( 'Webinar Data', 'rwmb' ),
'pages' => array( 'webinar' ),
'context' => 'normal',
'priority' => 'high',
'autosave' => true,
'fields' => array(
array(
'name' => __( 'Date of Webinar', 'rwmb' ),
'id' => "webinar_date",
'type' => 'date',
// jQuery date picker options. See here http://api.jqueryui.com/datepicker
'js_options' => array(
'dateFormat' => __( 'dd-MM-yy', 'rwmb' ),
'changeMonth' => true,
'changeYear' => true,
'showButtonPanel' => true,
),
),
array(
'name' => __( 'Location', 'rwmb' ),
'id' => "webinar-location",
'type' => 'text',
'std' => __( 'Default text value', 'rwmb' ),
),
array(
'name' => __( 'Time Of Webinar', 'rwmb' ),
'id' => 'webinar_time',
'type' => 'time',
'js_options' => array(
'stepMinute' => 5,
'showSecond' => true,
'stepSecond' => 10,
),
),
array(
'name' => __( 'Select Time Zone', 'rwmb' ),
'id' => "select-timezone",
'type' => 'select_advanced',
'options' => array(
'value1' => __( 'PST', 'rwmb' ),
'value2' => __( 'EST', 'rwmb' ),
),
'multiple' => false,
'placeholder' => __( 'Select an Coures Type', 'rwmb' ),
),
// URL
array(
'name' => __( 'Webinar URL', 'rwmb' ),
'id' => "webinar_url",
'type' => 'url',
'std' => 'http://google.com',
),
array(
'name' => __( 'Webinar Banner', 'rwmb' ),
'id' => "webinar_banner",
'type' => 'thickbox_image',
),
),
);
return $meta_boxes;
}
You can find more detail about meta boxes here.
Here is sample add_meta_box code:-
add_meta_box(
'some_meta_box_name'
,__( 'Some Meta Box Headline', 'plugin_textdomain' )
,'render_meta_box_content' //this is callback function.
,'post_type'
,'advanced'
,'high'
);