Advice on Error: Array to string conversion. Wordpress
Advice on Error: Array to string conversion. Wordpress
我一直在寻找解决此错误的方法。我只是想得到一些建议,因为我认为这是我所缺少的一些小东西。
我正在尝试从使用 ACF pro 设置的选项页面获取 url 字段和图像字段,使用灵活的内容。我正在获取数据,但不是作为字符串变量。
这是错误的屏幕截图。
新 LINK http://redrocketwebsitedesign.co.uk/Array_error2.png
以及生成此代码的代码。
<ul class="list-inline"><li>
<p>Follow us on</p>
</li>
<?php //Options: Social icons
// check if the flexible content field has rows of data
if( have_rows('social_icon', 'option') ):
// loop through the rows of data
while ( have_rows('social_icon', 'option') ) : the_row();
if( get_row_layout() == 'social_icon' ):
$image = get_sub_field_object('social_image', 'option');
if( $image ){
?>
<li>
<a href="<?php echo the_sub_field('social_link', 'option'); ?>" target="_blank">
<img class="img img-responsive" src="<?php echo $image[7]; ?>" alt="<?php echo $image[alt]; ?>"/>
</a>
<?php var_dump('Vardump <br />') ?>
<?php var_dump($url) ?>
<?php var_dump('<br /> Image array <br />') ?>
<?php var_dump($image) ?>
<?php var_dump('<br /> Image link <br />') ?>
<?php var_dump($image['7']) ?>
</li>
<?php
}
endif;
endwhile;
else :
// no layouts found
endif;
?>
</ul>
任何帮助将不胜感激:-]
$social_image 是 $field_name,并存储为图像数组。当我 print_r $image 时,这是 result.I 认为我接近能够从数组中选择正确的字符串。
Image array
`" array(22) { ["ID"]=> int(138) ["key"]=> string(19) "field_54e47a9b7f735" ["label"]=> string(12) "Social Image" ["name"]=> string(12) "social_image" ["prefix"]=> string(0) "" ["type"]=> string(5) "image" ["value"]=> array(18) { ["ID"]=> int(105) ["id"]=> int(105) ["title"]=> string(11) "Tripadvisor" ["filename"]=> string(24) "footertripadvisorNEW.png" ["url"]=> string(83) "http-link" ["alt"]=> string(11) "Tripadvisor" ["author"]=> string(1) "1" ["description"]=> string(0) "" ["caption"]=> string(0) "" ["name"]=> string(20) "footertripadvisornew" ["date"]=> string(19) "2015-02-10 16:13:27" ["modified"]=> string(19) "2015-02-18 11:52:15" ["mime_type"]=> string(9) "image/png" ["type"]=> string(5) "image" ["icon"]=> string(68) "http://localhost:8888/wordpress/wp-includes/images/media/default.png" ["width"]=> int(50) ["height"]=> int(50) ["sizes"]=>`
..等等
您的问题是您使用的 2 个变量之一在线
$value = get_sub_field( $field_name, $format_value );
当函数需要一个字符串时是一个数组。
在那之前的行中,您可以添加此代码并复制并粘贴输出...
print_r( $field_name ); echo '<br>'; print_r( $format_value );
这样我们就会知道这些变量中存储了什么。
get_sub_field() 接受一个 string
类型的参数。你目前传递的太多了。你应该使用:
$value = get_sub_field( $field_name );
此外,如前所述,您需要确保 $field_name
实际上是一个字符串,而不是数组。
我一直在寻找解决此错误的方法。我只是想得到一些建议,因为我认为这是我所缺少的一些小东西。
我正在尝试从使用 ACF pro 设置的选项页面获取 url 字段和图像字段,使用灵活的内容。我正在获取数据,但不是作为字符串变量。
这是错误的屏幕截图。 新 LINK http://redrocketwebsitedesign.co.uk/Array_error2.png
以及生成此代码的代码。
<ul class="list-inline"><li>
<p>Follow us on</p>
</li>
<?php //Options: Social icons
// check if the flexible content field has rows of data
if( have_rows('social_icon', 'option') ):
// loop through the rows of data
while ( have_rows('social_icon', 'option') ) : the_row();
if( get_row_layout() == 'social_icon' ):
$image = get_sub_field_object('social_image', 'option');
if( $image ){
?>
<li>
<a href="<?php echo the_sub_field('social_link', 'option'); ?>" target="_blank">
<img class="img img-responsive" src="<?php echo $image[7]; ?>" alt="<?php echo $image[alt]; ?>"/>
</a>
<?php var_dump('Vardump <br />') ?>
<?php var_dump($url) ?>
<?php var_dump('<br /> Image array <br />') ?>
<?php var_dump($image) ?>
<?php var_dump('<br /> Image link <br />') ?>
<?php var_dump($image['7']) ?>
</li>
<?php
}
endif;
endwhile;
else :
// no layouts found
endif;
?>
</ul>
任何帮助将不胜感激:-]
$social_image 是 $field_name,并存储为图像数组。当我 print_r $image 时,这是 result.I 认为我接近能够从数组中选择正确的字符串。
Image array
`" array(22) { ["ID"]=> int(138) ["key"]=> string(19) "field_54e47a9b7f735" ["label"]=> string(12) "Social Image" ["name"]=> string(12) "social_image" ["prefix"]=> string(0) "" ["type"]=> string(5) "image" ["value"]=> array(18) { ["ID"]=> int(105) ["id"]=> int(105) ["title"]=> string(11) "Tripadvisor" ["filename"]=> string(24) "footertripadvisorNEW.png" ["url"]=> string(83) "http-link" ["alt"]=> string(11) "Tripadvisor" ["author"]=> string(1) "1" ["description"]=> string(0) "" ["caption"]=> string(0) "" ["name"]=> string(20) "footertripadvisornew" ["date"]=> string(19) "2015-02-10 16:13:27" ["modified"]=> string(19) "2015-02-18 11:52:15" ["mime_type"]=> string(9) "image/png" ["type"]=> string(5) "image" ["icon"]=> string(68) "http://localhost:8888/wordpress/wp-includes/images/media/default.png" ["width"]=> int(50) ["height"]=> int(50) ["sizes"]=>`
..等等
您的问题是您使用的 2 个变量之一在线
$value = get_sub_field( $field_name, $format_value );
当函数需要一个字符串时是一个数组。
在那之前的行中,您可以添加此代码并复制并粘贴输出...
print_r( $field_name ); echo '<br>'; print_r( $format_value );
这样我们就会知道这些变量中存储了什么。
get_sub_field() 接受一个 string
类型的参数。你目前传递的太多了。你应该使用:
$value = get_sub_field( $field_name );
此外,如前所述,您需要确保 $field_name
实际上是一个字符串,而不是数组。