doureng5668 2019-06-20 05:54
浏览 83

自定义帖子类型分类法上的ACF转发器字段返回错误(Timber主题)

I have created a custom post type and its taxonomy. I also have ACF repeater image field to the taxonomy, but every time when I add image to the field, there are errors like this.

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

This is the query in 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;

This is the var_dump of $terms

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"
    }
  }
}

This is in twig:

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

This is acf for custom post type taxonomy

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;

If i remove images from the field, errors are gone. I haven't figured out yet for a solution. Does anyone have any idea?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算