Support

Account

Home Forums ACF PRO Gallery – Illegal string offsets

Solved

Gallery – Illegal string offsets

  • I am trying to create a gallery.

    1. I register fields via PHP

    acf_add_local_field_group(array(
    		'key' => 'group_post_gallery',
    		'title' => esc_html__( 'Gallery', 'lilio' ),
    		'fields' => array(
    			array(
    				'key' => 'field_post_gallery',
    				'label' => esc_html__( 'Images', 'lilio' ),
    				'name' => 'my_post_gallery',
    				'type' => 'gallery',
    				'instructions' => '',
    				'required' => 0,
    				'conditional_logic' => 0,
    				'wrapper' => array(
    					'width' => '',
    					'class' => '',
    					'id' => '',
    				),
    				'min' => '',
    				'max' => '',
    				'insert' => 'append',
    				'library' => 'all',
    				'min_width' => '',
    				'min_height' => '',
    				'min_size' => '',
    				'max_width' => '',
    				'max_height' => '',
    				'max_size' => '',
    				'mime_types' => '',
    			),
    		),
    		'location' => array(
    			array(
    				array(
    					'param' => 'post_type',
    					'operator' => '==',
    					'value' => 'post',
    				),
    				array(
    					'param' => 'post_format',
    					'operator' => '==',
    					'value' => 'gallery',
    				),
    			),
    		),
    		'menu_order' => 0,
    		'position' => 'acf_after_title',
    		'style' => 'default',
    		'label_placement' => 'top',
    		'instruction_placement' => 'label',
    		'hide_on_screen' => '',
    		'active' => 1,
    		'description' => '',
    	));

    2. Added code from https://www.advancedcustomfields.com/resources/gallery/ > Basic list of images

    <?php 
    
    $images = get_field('gallery');
    $size = 'full'; // (thumbnail, medium, large, full or custom size)
    
    if( $images ): ?>
        <ul>
            <?php foreach( $images as $image ): ?>
                <li>
                	<?php echo wp_get_attachment_image( $image['ID'], $size ); ?>
                </li>
            <?php endforeach; ?>
        </ul>
    <?php endif; ?>

    Errors:
    Warning: Illegal string offset ‘ID’ in …

    What is wrong ?

  • OK, I found solution.
    I used is_admin() function and this cause a problem.

    // Before
    if ( is_admin() ) {
    	require_once get_template_directory() . '/core/custom-fields.php';
    }
    
    // After
    require_once get_template_directory() . '/core/custom-fields.php';
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Gallery – Illegal string offsets’ is closed to new replies.