• tango3

    (@tango3)


    Just been looking at the documentation on Conditional Logic in the ‘contains’ section, I’m trying to add a array of values for a set of checkbox fields, so the field is visible is any of the ids are set(via a checkbox)
    the documentation says use the following:
    'visible' => array('brand', 'contains', ['Apple'])

    but it throws a fatal error when I use the following:

    $meta_boxes[] = array(
    		'id'         => 'he_subtitle',
    		'title'      => __( 'HE Sub-Title', 'he_subtitle' ),
                    'post_types' => 'courses',
    		'priority'   => 'low',
    		'autosave'   => true,
                    'context'    => 'side',
                    'visible' => array('course_type_select', 'contains', ['32','35']),
    
    		'fields'     => array(
    			// Course reference code
    			array(
    				'name'  => __( '' ),
    				'id'    => "{$prefix}he_subtitle",
    				'desc'  => __( 'HE sub-title (Year of entry)' ),
    				'type'  => 'text',
    			),
            ),
        );

    I also tried array() instead of [] which sorts the error but still doesn’t work, the only way i can get to to work is to use a single ID value.

    https://www.ads-software.com/plugins/meta-box/

Viewing 1 replies (of 1 total)
  • Plugin Contributor Tan Nguyen

    (@tanng)

    Hi bro,

    The contains operator is for single value, it return true when your field contains a value, in case your field is an array, it will works if your array contains your value. If your field is string, it will works if your string contains your value

    For example:

    [‘a’, ‘b’] contains ‘a’ but not contains ‘c’
    ‘hello world!’ contains ‘hello’ but not contains ‘foo’

    In your case, to check if a field is one of those values, use in instead

    array(‘course_type_select’, ‘in’, [32, 35])

    Btw, square brackets only available for PHP >= 5.4

    Regards

Viewing 1 replies (of 1 total)
  • The topic ‘Conditional Logic: contains array throwing fatal error’ is closed to new replies.