Related
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' ),
),
)
)
)
));
I just upgraded our server and it has the latest version of php. When users try to log in to our website we get the following error:
The staging.ilovenz.me page isn’t working
staging.ilovenz.me didn’t send any data.
ERR_EMPTY_RESPONSE
I have checked the log files and we have the following error:
[28-Feb-2017 22:23:33 UTC] PHP Warning: in_array() expects parameter 2 to be array, boolean given in /mnt/stor14-wc1-dfw3/staging.ilovenz.me/web/content/wp-content/themes/kleo/lib/options.php on line 2416
After looking at the file on line 2416 I can see the following function, which I have no Idea what to do with it... Some help would be amazing!
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
$sections[] = array(
'icon' => 'el-icon-shopping-cart',
'icon_class' => 'icon-large',
'title' => __( 'Woocommerce', 'kleo_framework' ),
'customizer' => false,
'desc' => '',
'fields' => array(
array(
'id' => 'woo_sidebar',
'type' => 'select',
'compiler' => true,
'title' => __( 'Woocommerce Pages Layout', 'kleo_framework' ),
'subtitle' => __( 'Select the layout to use in Woocommerce pages.', 'kleo_framework' ),
'options' => array(
'default' => 'Default site layout',
'no' => 'Full width',
'left' => 'Left Sidebar',
'right' => 'Right Sidebar',
'3lr' => '3 Column, Left and Right Sidebars',
'3ll' => '3 Column, 2 Left sidebars',
'3rr' => '3 Column, 2 Right sidebars'
),
'default' => 'default'
),
array(
'id' => 'woo_cat_sidebar',
'type' => 'select',
'compiler' => true,
'title' => __( 'Woocommerce Category Layout', 'kleo_framework' ),
'subtitle' => __( 'Select the layout to use in Woocommerce product listing pages.', 'kleo_framework' ),
'options' => array(
'default' => 'Default as set above',
'no' => 'Full width',
'left' => 'Left Sidebar',
'right' => 'Right Sidebar',
'3lr' => '3 Column, Left and Right Sidebars',
'3ll' => '3 Column, 2 Left sidebars',
'3rr' => '3 Column, 2 Right sidebars'
),
'default' => 'default'
),
array(
'id' => 'woo_single_sidebar',
'type' => 'select',
'compiler' => true,
'title' => __( 'Woocommerce Single Product Layout', 'kleo_framework' ),
'subtitle' => __( 'Select the layout to use in Woocommerce single product pages.', 'kleo_framework' ),
'options' => array(
'default' => 'Default as set above',
'no' => 'Full width',
'left' => 'Left Sidebar',
'right' => 'Right Sidebar',
'3lr' => '3 Column, Left and Right Sidebars',
'3ll' => '3 Column, 2 Left sidebars',
'3rr' => '3 Column, 2 Right sidebars'
),
'default' => 'default'
),
array(
'id' => 'woo_cart_location',
'type' => 'button_set',
'title' => __( 'Menu cart location', 'kleo_framework' ),
'subtitle' => __( 'Shopping Cart in header menu location', 'kleo_framework' ),
'options' => array(
'off' => 'Disabled',
'primary' => 'Primary menu',
'secondary' => 'Secondary menu',
'top' => 'Top menu'
),
'default' => 'primary'
),
array(
'id' => 'woo_mobile_cart',
'type' => 'switch',
'title' => __( 'Mobile menu Cart Icon', 'kleo_framework' ),
'subtitle' => __( 'This will show on mobile menu a shop icon with the number of cart items', 'kleo_framework' ),
'default' => '1' // 1 = checked | 0 = unchecked
),
array(
'id' => 'woo_image_effect',
'type' => 'button_set',
'title' => __( 'Product image effect', 'kleo_framework' ),
'subtitle' => __( 'The effect on products listing when hovering an image.', 'kleo_framework' ),
'options' => array(
'default' => 'Bottom-Top',
'fade' => 'Fade',
'alt' => 'Left-Right',
'single' => 'No effect'
),
'default' => 'default'
),
array(
'id' => 'woo_product_animate',
'type' => 'switch',
'title' => __( 'Enable product listing Appear Animation', 'kleo_framework' ),
'subtitle' => __( 'On product listing the products will have a appear animation.', 'kleo_framework' ),
'default' => '1' // 1 = checked | 0 = unchecked
),
array(
'id' => 'woo_percentage_badge',
'type' => 'switch',
'title' => __( 'Show percentage badge on products list', 'kleo_framework' ),
'subtitle' => __( 'This will replace the "Sale" badge with "SAVE UP TO xx%"', 'kleo_framework' ),
'default' => '0' // 1 = checked | 0 = unchecked
),
array(
'id' => 'woo_percent_color',
'type' => 'color',
'required' => array( 'woo_percentage_badge', '=', '1' ),
'title' => __( 'Custom Badge color', 'kleo_framework' ),
'subtitle' => '',
'default' => '#ffffff' // 1 = checked | 0 = unchecked
),
array(
'id' => 'woo_percent_bg',
'type' => 'color',
'required' => array( 'woo_percentage_badge', '=', '1' ),
'title' => __( 'Custom Badge Background', 'kleo_framework' ),
'subtitle' => '',
'default' => '#000000' // 1 = checked | 0 = unchecked
),
array(
'id' => 'woo_free_badge',
'type' => 'switch',
'title' => __( 'Show free badge on products list', 'kleo_framework' ),
'default' => '1' // 1 = checked | 0 = unchecked
),
array(
'id' => 'woo_new_badge',
'type' => 'switch',
'title' => __( 'Show NEW badge for new products added', 'kleo_framework' ),
'subtitle' => '',
'default' => '1' // 1 = checked | 0 = unchecked
),
array(
'id' => 'woo_show_excerpt_single',
'type' => 'switch',
'title' => __( 'Show excerpt on product page', 'kleo_framework' ),
'subtitle' => '',
'default' => '0' // 1 = checked | 0 = unchecked
),
array(
'id' => 'woo_product_navigation',
'type' => 'switch',
'title' => __( 'Enable product navigation', 'kleo_framework' ),
'subtitle' => 'Display previous and next product navigation',
'default' => '1' // 1 = checked | 0 = unchecked
),
array(
'id' => 'woo_buddypress_menus',
'type' => 'switch',
'title' => __( 'Manage account in Buddypress', 'kleo_framework' ),
'subtitle' => __( 'Integrates "My Account" into Buddypress profile tabs', 'kleo_framework' ),
'default' => '1' // 1 = checked | 0 = unchecked
),
array(
'id' => 'woo_new_days',
'type' => 'text',
'required' => array( 'woo_new_badge', '=', '1' ),
'title' => __( 'Number of days to treat a product as new', 'kleo_framework' ),
'subtitle' => __( 'For how many days to show the NEW badge once a product is added to the shop.', 'kleo_framework' ),
'default' => '7' // 1 = checked | 0 = unchecked
),
array(
'id' => 'woo_catalog',
'type' => 'button_set',
'title' => __( 'Catalog mode', 'kleo_framework' ),
'subtitle' => __( 'If you enable catalog mode will disable Add To Cart buttons, Checkout and Shopping cart.', 'kleo_framework' ),
'options' => array(
'0' => 'No',
'1' => 'Yes'
),
'default' => '0'
),
array(
'id' => 'woo_disable_prices',
'type' => 'button_set',
'title' => __( 'Disable prices', 'kleo_framework' ),
'subtitle' => __( 'Disable prices on category pages and product page', 'kleo_framework' ),
'options' => array(
'0' => 'No',
'1' => 'Yes'
),
'required' => array( 'woo_catalog', '=', '1' ),
'default' => '0'
),
array(
'id' => 'woo_shop_columns',
'type' => 'select',
'title' => __( 'Shop Products Columns', 'kleo_framework' ),
'subtitle' => __( 'Select the number of columns to use for products display.', 'kleo_framework' ),
'options' => array(
'3' => '3',
'4' => '4',
'5' => '5',
'6' => '6'
),
'default' => '3'
),
array(
'id' => 'woo_shop_products',
'type' => 'text',
'title' => __( 'Shop Products per page', 'kleo_framework' ),
'subtitle' => __( 'How many products to show per page', 'kleo_framework' ),
'default' => '15' // 1 = checked | 0 = unchecked
),
array(
'id' => 'woo_related_columns',
'type' => 'select',
'title' => __( 'Related Products number', 'kleo_framework' ),
'subtitle' => __( 'Select the number of related products to show on product page.', 'kleo_framework' ),
'options' => array(
'3' => '3',
'4' => '4',
'5' => '5',
'6' => '6'
),
'default' => '3'
),
array(
'id' => 'woo_upsell_columns',
'type' => 'select',
'title' => __( 'Upsell Products number', 'kleo_framework' ),
'subtitle' => __( 'Select the number of upsell products to show on product page.', 'kleo_framework' ),
'options' => array(
'3' => '3',
'4' => '4',
'5' => '5',
'6' => '6'
),
'default' => '3'
),
array(
'id' => 'woo_cross_columns',
'type' => 'select',
'title' => __( 'Cross-sell Products number', 'kleo_framework' ),
'subtitle' => __( 'Select the number of Cross-sell products to show on cart page.', 'kleo_framework' ),
'options' => array(
'3' => '3',
'4' => '4',
'5' => '5',
'6' => '6'
),
'default' => '3'
)
)
);
}
add_filter( 'rwmb_meta_boxes', 'your_prefix_meta_boxes' );
function your_prefix_meta_boxes( $meta_boxes ) {
$meta_boxes[] = array(
'title' => __( 'Test Meta Box', 'textdomain' ),
'post_types' => 'post',
'fields' => array(
array(
'id' => 'name',
'name' => __( 'Name', 'textdomain' ),
'type' => 'text',
),
array(
'id' => 'gender',
'name' => __( 'Gender', 'textdomain' ),
'type' => 'radio',
'options' => array(
'm' => __( 'Male', 'textdomain' ),
'f' => __( 'Female', 'textdomain' ),
),
),
array(
'id' => 'email',
'name' => __( 'Email', 'textdomain' ),
'type' => 'email',
),
),
);
return $meta_boxes;
}
i had pud this code in my function.php and i am getting meta box in add new post only. i need meta box also on my page. please help me out
You should select one of the hooks available on your pages and to add your function there. For example use page_template hook:
add_filter( 'page_template', 'your_prefix_meta_boxes' );
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'
);
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'
)
)
);