我創建了一個名爲「albums」的自定義帖子類型。我在每篇文章中有5個自定義字段。 3個文本字段,1個圖像字段和1個文件上傳字段。我在我的模板頁面中正確地獲取了3個文本值。但我無法獲取圖片和文件上傳字段的網址部分。 這裏是我的代碼:如何在高級自定義字段wordpress post中獲取圖片url
<?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
鳥
杜鵑
66,2668245306_027a56fe50_b,,,圖像/ JPEG, http://localhost/YIB/wordpress/wp-content/uploads/2016/03/2668245306_027a56fe50_b-1.jpg, 1024,768 ,Array
樣品樣品樣品樣品樣品樣品樣品
18, ,eudynamys-scolopacea,「eudynamys-scolopacea」,audio/mpeg, http://localhost/YIB/wordpress/wp-content/uploads/2016/03/eudynamys-scolopacea.mp3
其工作,如果我們使用get_field而不是get_the_field –
是的抱歉..對於acf它的get_field –