【发布时间】:2017-09-02 10:32:19
【问题描述】:
我已经为自定义帖子类型创建了自定义字段。当我检索返回 22 的主题模板图像值中的值时。 如何获取图片网址?
<?php
$args = array(
'posts_per_page' => -1,
'post_type' => 'projects',
'post_status' => 'publish',
);
$projects = get_posts( $args );
foreach ($projects as $project) {
echo $project->project_title; // Title Text
echo $project->project_description; // Description Content
echo $project->project_image; // 22
} ?>
当我打印 $project 时
WP_Post Object
(
[ID] => 35
[post_author] => 1
[post_date] => 2017-04-07 05:50:29
[post_date_gmt] => 2017-04-07 05:50:29
[post_content] => Tekzenit
[post_title] => Tekzenit
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => tekzenit
[to_ping] =>
[pinged] =>
[post_modified] => 2017-04-07 06:12:54
[post_modified_gmt] => 2017-04-07 06:12:54
[post_content_filtered] =>
[post_parent] => 0
[guid] => http://10.180.82.8/fareed/?post_type=projects&p=35
[menu_order] => 0
[post_type] => projects
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
【问题讨论】:
-
你的问题不够清楚。您是否为自定义帖子类型创建了自定义元字段(project_title、project_description、project_image)?你也得到了 project_title 和 project_description 的值吗?
-
您是否记得将 ACF 设置为返回 URL 或对象?如果您没有设置它,它可能只是返回 ID。
标签: php wordpress wordpress-theming advanced-custom-fields custom-fields