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';
The topic ‘Gallery – Illegal string offsets’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.