Php 如何在高级自定义字段wordpress post中获取图像url
我创建了一个名为“albums”的自定义帖子类型。我有5个自定义字段在我的每个职位。3个文本字段、1个图像字段和1个文件上载字段。我在我的模板页面中得到了3个正确的文本值。但我无法获取图像和文件上传字段的url部分。 这是我的密码:Php 如何在高级自定义字段wordpress post中获取图像url,php,wordpress,advanced-custom-fields,Php,Wordpress,Advanced Custom Fields,我创建了一个名为“albums”的自定义帖子类型。我有5个自定义字段在我的每个职位。3个文本字段、1个图像字段和1个文件上载字段。我在我的模板页面中得到了3个正确的文本值。但我无法获取图像和文件上传字段的url部分。 这是我的密码: <?php $posts = get_posts(array( 'post_type' => 'albums' )); if($posts) { echo '<ul>'; foreach($posts as $post) { e
<?php
$posts = get_posts(array(
'post_type' => 'albums'
));
if($posts)
{
echo '<ul>';
foreach($posts as $post)
{
echo '<li><a href="' . get_permalink($post->ID) . '">' . get_the_title($post->ID) . '</a></li>';
the_field('album_category'); echo "<br>";
the_field('album_name'); echo "<br>";
the_field('slide_name'); echo "<br>";
the_field('slide_description'); echo "<br>";
the_field('audio_file'); echo "<br>";
}
echo '</ul>';
}
?>
这是我当前的输出
布谷鸟-1鸟类
布谷鸟
662668245306_027; a56fe50_b.,图像/jpeg, , 1024768,数组
样本
18, ,Eudynamis scolopacea,“Eudynamis scolopacea”,音频/mpeg, 试试这个
<?php
$imgurl = get_field('slide_image',$post->ID);
if (filter_var($imgurl, FILTER_VALIDATE_URL) === FALSE)
{
$imgurl = wp_get_attachment_url($imgurl);
}
echo '<img src="' . $imgurl . '" alt="image">';
?>
试试这个
图像字段和文件字段正在返回数组,因此
$image_m = get_field('slide_description');
$image_a = get_field('audio_file');
echo '<pre>';
print_r($image_m);
print_r($image_a);
echo '</pre>';
然后写
而不是在删除if语句后重试..你的图像字段是否返回int值?你能给我发送管理设置中字段的屏幕截图吗?如果我们使用get_字段而不是get_字段,它会起作用
array(
['name'] => 'test';
['url'] => 'http://example.mp3';
)