自定义帖子类型分类中的ACF转发器字段返回错误(木材主题)

时间:2019-06-20 05:54:00

标签: php wordpress advanced-custom-fields timber

我创建了一个自定义帖子类型及其分类。分类中也有ACF中继器图像字段,但是每次将图像添加到该字段时,都会出现类似这样的错误。

PHP Notice:  Array to string conversion in /var/www/html/wp/wp-includes/class-wp-tax-query.php on line 558
PHP Notice:  Array to string conversion in /var/www/html/wp/wp-includes/taxonomy.php on line 933

Warning: preg_match() expects parameter 2 to be string, array given 
in /var/www/html/wp/wp-includes/formatting.php on line 1597

Warning: strip_tags() expects parameter 1 to be string, array given 
in /var/www/html/wp/wp-includes/formatting.php on line 2207

这是php中的查询:

$terms = new Timber\Term();


$args = array(
    'posts_per_page' => -1,
    'orderby' => 'title',
    'order' => 'ASC',
    'post_type' => 'apartments',
    'post_status'    => 'publish',
    'tax_query' => array(
        array(
            'taxonomy' => 'apartment_category',
            'field' => 'slug',
            'terms' => $terms,
        )
    )
);


$tax_apartments = new Timber\PostQuery($args);

$context['tax_apartments'] = $tax_apartments;
$context['apartment_name'] = $terms->name;
$context['apartment_image'] = $terms->apartment_image;

这是$ terms的var_dump

object(Timber\Term)#7418 (20) {
  ["PostClass"]=>
  string(11) "Timber\Post"
  ["TermClass"]=>
  string(4) "Term"
  ["object_type"]=>
  string(4) "term"
  ["_children"]=>
  NULL
  ["name"]=>
  string(6) "A-apartment"
  ["taxonomy"]=>
  string(18) "apartment_category"
  ["id"]=>
  int(12)
  ["ID"]=>
  int(12)
  ["term_id"]=>
  int(12)
  ["slug"]=>
  string(6) "a-apartment"
  ["term_group"]=>
  int(0)
  ["term_taxonomy_id"]=>
  int(12)
  ["parent"]=>
  int(0)
  ["count"]=>
  int(7)
  ["filter"]=>
  string(3) "raw"
  ["term_order"]=>
  string(1) "0"  
  ["apartment_image"]=>
  array(3) {
    [0]=>
    array(1) {
      ["building_image"]=>
      string(58) "http://localhost/content/uploads/2019/05/subpage-lift2.jpg"
    }
    [1]=>
    array(1) {
      ["building_image"]=>
  string(57) "http://localhost/content/uploads/2019/05/subpage-lift.jpg"
    }
    [2]=>
    array(1) {
      ["building_image"]=>
      string(51) "http://localhost/content/uploads/2019/05/square.png"
    }
  }
}

这是树枝:

{% for photo in apartment_image %}
    <div class="col-md-4">
     <img src="{{photo['building_image']}}" alt="">
    </div>
{% endfor %}

这是自定义帖子类型分类法的acf

if( function_exists('acf_add_local_field_group') ):

acf_add_local_field_group(array(
'key' => 'group_5cfa36fe90c69',
'title' => 'Apartment info',
'fields' => array(
    array(
        'key' => 'field_5cfa3a1c52062',
        'label' => 'Images',
        'name' => 'apartment_image',
        'type' => 'repeater',
        'instructions' => '',
        'required' => 0,
        'conditional_logic' => 0,
        'wrapper' => array(
            'width' => '',
            'class' => '',
            'id' => '',
        ),
        'collapsed' => '',
        'min' => 0,
        'max' => 0,
        'layout' => 'table',
        'button_label' => '',
        'sub_fields' => array(
            array(
                'key' => 'field_5cfa3a4d52063',
                'label' => 'Buiding Image',
                'name' => 'building_image',
                'type' => 'image',
                'instructions' => '',
                'required' => 0,
                'conditional_logic' => 0,
                'wrapper' => array(
                    'width' => '',
                    'class' => '',
                    'id' => '',
                ),
                'return_format' => 'url',
                'preview_size' => 'thumbnail',
                'library' => 'all',
                'min_width' => '',
                'min_height' => '',
                'min_size' => '',
                'max_width' => '',
                'max_height' => '',
                'max_size' => '',
                'mime_types' => '',
            ),
        ),
    ),
),
'location' => array(
    array(
        array(
            'param' => 'taxonomy',
            'operator' => '==',
            'value' => 'apartment_category',
        ),
    ),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => true,
'description' => '',
));

endif;

如果我从现场移除图像,错误就会消失。我还没有想办法。有人知道吗?

0 个答案:

没有答案