Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when "Default" parameter is set to "date"! #826

Closed
codespacing opened this issue Dec 28, 2016 · 1 comment
Closed

Error when "Default" parameter is set to "date"! #826

codespacing opened this issue Dec 28, 2016 · 1 comment

Comments

@codespacing
Copy link

codespacing commented Dec 28, 2016

Hi,

I create a WP plugin. If i set the default value of a "select" field to "date", WP returns an error saying:

date() expects parameter 1 to be string, array given on line 283 in file --\wp-content\plugins--\includes\CMB2_Base.php

As you notice, the error is located in the file "CMB2_Base.php" on line "283"

Code Example:

add_action( 'cmb2_admin_init', 'cs_register_demo_metabox' );
function cs_register_demo_metabox() {

	$cmb = new_cmb2_box( array(
		'id'           => 'box_id',
                'title'        => 'Title',
	) );

	$cmb->add_field( array(
		'id' => 'orderby_param',
		'name' => 'Orderby parameters', 
		'desc' => 'Sort retrieved posts by parameter. Defaults to "date". ',
		'type' => 'select',
		'default' => 'date',
		'options' => array(
				'none' => 'No order',
				'ID' => 'Order by post id',
				'author' => 'Order by author',
				'name' => 'Order by title',
				'name' => 'Order by post name (post slug)',
				'date' => 'Order by date',
				'modified' => 'Order by last modified date',
				'parent' => 'Order by post/page parent id',
				'rand' => 'Random order',
				'comment_count' => 'Order by number of comments',
				'menu_order' => 'Order by Page Order',
				'meta_value' => 'Order by string meta value',
				'meta_value_num' => 'Order by numeric meta value ',
				'post__in' => 'Preserve post ID order given in the post__in array',
		)
	) );
	
}

Thank you very much for your help ;)

@jtsternberg
Copy link
Member

That is a known issue, unfortunately, but the workaround is documented here: https://github.com/WebDevStudios/CMB2/wiki/Troubleshooting#callable-field-parameters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants