Show group
-
$entries = get_post_meta( get_the_ID(), 'gg_elementos', true ); foreach ( (array) $entries as $key => $entry ) { $title = $desc = ''; if ( isset( $entry['gg_titulo'] ) ) $title = esc_html( $entry['gg_titulo'] ); if ( isset( $entry['gg_textmoney'] ) ) $desc = esc_html( $entry['gg_textmoney'] ); } echo $title;Why don’t show anything?
-
One thing to keep in mind is that those variables are getting overwritten in each iteration of your foreach loop. It’s possible both values in the if statements are empty on the last iteration, causin you to have the empty $title variable.
You were right, thanks.
A further problem. When I selected a date returns this error:Notice: Array to string conversion in \wordpress\wp-content\themes\theme\metabox\includes\CMB2_Utils.php on line 131 Notice: Array to string conversion in \wordpress\wp-content\themes\theme\metabox\includes\CMB2_Utils.php on line 120But when I remove the option:
'repeatable' => truesimply is not saved.Could you provide the settings you’re using for this field? Curious about that Array to string issues.
require_once dirname( __FILE__ ) . '/metabox/init.php'; add_action( 'cmb2_init', 'factura' ); function factura() { $prefix = 'gg_'; $cmb_group = new_cmb2_box( array( 'id' => $prefix . 'factura', 'title' => __( 'Servicios' ), 'object_types' => array( 'factura' ) ) ); $group_field_id = $cmb_group->add_field( array( 'id' => $prefix . 'demo', 'type' => 'group', 'options' => array( 'group_title' => __( 'Elemento {#}' ), 'add_button' => __( 'Añadir elemento' ), 'remove_button' => __( 'Eliminar elemnto' ), 'sortable' => true ) ) ); $cmb_group->add_group_field( $group_field_id, array( 'name' => __( 'Descripción' ), 'id' => $prefix . 'titulo', 'type' => 'text' ) ); $cmb_group->add_group_field( $group_field_id, array( 'name' => __( 'Fecha' ), 'id' => $prefix . 'textdate', 'type' => 'text_date_timestamp', 'repeatable' => true ) ); $cmb_group->add_group_field( $group_field_id, array( 'name' => __( 'Precio' ), 'id' => $prefix . 'textmoney', 'type' => 'text_money', 'after_field' => '€', 'before_field' => ' ', ) ); }Are you updated to the latest version of the plugin? Where/when are you seeing those errors appear?
I just tried on a dev site and things saved fine from what I can see.
No, I have version 2.1.0. It appears above the METABOX. A date appears when you save, if not to date shown no error.
With 2.1.2
Notice: Array to string conversion in \wordpress\wp-content\plugins\cmb2\includes\CMB2_Utils.php on line 152 Notice: Array to string conversion in \wordpress\wp-content\plugins\cmb2\includes\CMB2_Utils.php on line 141Not managing to reproduce on my own install, sadly.
The two lines referenced above come from in the following:
/** * Returns a timestamp, first checking if value already is a timestamp. * @since 2.0.0 * @param string|int $string Possible timestamp string * @return int Time stamp */ public function make_valid_time_stamp( $string ) { if ( ! $string ) { return 0; } return $this->is_valid_time_stamp( $string ) ? (int) $string : strtotime( (string) $string ); } /** * Determine if a value is a valid timestamp * @since 2.0.0 * @param mixed $timestamp Value to check * @return boolean Whether value is a valid timestamp */ public function is_valid_time_stamp( $timestamp ) { return (string) (int) $timestamp === (string) $timestamp && $timestamp <= PHP_INT_MAX && $timestamp >= ~PHP_INT_MAX; }Line 141 is “strtotime( (string) $string );” and line 152 is: “&& $timestamp <= PHP_INT_MAX”.
Not sure why it’s getting an array passed in.
If you use the option to repeat, it returns the error. And if you do not use, it is saved when he wants.
I tried on another website and still going the same, with a new theme.
Want to make a video demo? With mail…
Sure, if you want to. I’ve been copying what you’ve provided exactly, except for the object type, and just not seeing the error.
As a thought, I’m curious if you’ve somehow got old data for the keys saved, and that’s what’s getting fetched. Have you tried other CMB2 fields using the same key, with this test post you’re using? Or is this happening on a brand new published post?
I’ve been testing and I have not discovered the error. Finally I decided to use jQuery Datapicker. Its works.
At this point, do what ya gotta do for a working solution. Wish I knew what was going on with it though, in case it was a bug coming from the plugin itself.
I found the error. Only it appears if you use “dd / mm / yy”. The error occurs when you choose dates where the day is over 12.
Example:
6/10/15 choose, beware.
8/13/15 choose, is not saved.Odd, but at the same time if you’re using that format, then the 13 would be the month, not the day, as well.
oh, sorry, yes.
When i choose 13/08/15, is not saved.
The topic ‘Show group’ is closed to new replies.