高级自定义字段 the_sub_field()['url'] 但它不返回 URL [英] Advanced Custom Fields the_sub_field()['url'] but it doesn't return the URL

查看:22
本文介绍了高级自定义字段 the_sub_field()['url'] 但它不返回 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是对这个问题的跟进

高级自定义字段获取子字段图片><块引用>

您可以使用 get_sub_field('imgcolumn_1')['url']; 获取图片的 URL;

作为函数 get_sub_field() 返回一个数组.

本文档https://www.advancedcustomfields.com/resources/the_sub_field/表示访问索引没有区别

确实如此

<块引用>

这个函数本质上和echo get_sub_field()一样

如果我去

<?php echo the_sub_field('agenda_event_speaker_headshot')['url'] ?>

img src unknown

如何在高级自定义字段的子字段中访问图像数组的 url 索引?

解决方案

很简单——我一开始没有在现场设置图像...

这实际上是正确的代码.

this is a follow up to this question advanced custom fields can't do nested loops repeater inside repeater have_rows() not doing anything

Now I'm stuck on a problem where I can't get the sub field URL.

          <div class="tc__agenda-speaker">
              <?php while (have_rows('agenda_event_speakers')) : the_row(); ?>
              <div class="tc__agenda-speaker-headshot">
                  <!-- DEBUG LINE -->
                  <div style="color: red;"><?php echo the_sub_field('agenda_event_speaker_headshot')['src'] ?></div>
                  <img src="<?php the_sub_field('agenda_event_speaker_headshot')['url'] ?>" alt="<?php the_sub_field('agenda_event_speaker_headshot')['alt'] ?>">
              </div>
              <div class="tc__agenda-speaker-info">
                  <h4><?php the_sub_field('agenda_event_speaker_name') ?></h4>
                  <p><?php the_sub_field('agenda_event_speaker_title') ?></p>
              </div>
              <?php endwhile ?>
          </div>
        <?php endif ?>

This line

<?php the_sub_field('agenda_event_speaker_headshot')['url'] ?>

It's output is this

16835, 16835, Name color 2, Name-color-2.png, 152744, http://website.com/wp-content/uploads/2021/02/Name-color-2.png, http://website.com/post/post-title-here/Name-color-2/, , 86, , , Name-color-2, inherit, 16799, 2021-02-02 16:45:53, 2021-02-02 16:45:53, 0, image/png, image, png, http://website.com/wp-includes/images/media/default.png, 500, 500, Array

The fields returns format is array

Advanced Custom Fields get sub field image

You can use get URL of Image by get_sub_field('imgcolumn_1')['url'];

As function get_sub_field() returns an array.

this documentation https://www.advancedcustomfields.com/resources/the_sub_field/ indicates there's no difference in accessing indexes

It does say

This function is essentially the same as echo get_sub_field()

If I go

<?php echo the_sub_field('agenda_event_speaker_headshot')['url'] ?>

the img src is unknown

How do you access url index of image array in a sub field in advanced custom fields?

解决方案

Very simple - i had no image set in the field in the first place...

This is in fact the correct code.

这篇关于高级自定义字段 the_sub_field()['url'] 但它不返回 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆