检索主题中自定义字段的图像URL

时间:2017-04-07 作者:Developer

我已经为自定义帖子类型创建了自定义字段。检索主题模板中的值时,图像值返回22。如何获取图像URL。?

<?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

     } ?>
打印$项目时

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
)

1 个回复
最合适的回答,由SO网友:rudtek 整理而成

你可以说:

get_the_post_thumbnail(\'\', \'full\')
仅从id本身开始,因为这是一个自定义元。

wp_get_attachment_image($project->project_image, \'full\')

相关推荐

如何让`wp-list-table`显示我在Custom-Post中的`Custom-Fields`

一切都好吗<我需要wp-list-table 也要显示custom-fields 在每个custom-post 我有,但我不知道如何做到这一点,在这幅图中,它显示了带有字段的表格:Title, Author and Publication Date: 我想要的是能够选择custom-fields 将出现,例如以下示例Title, Carta, Naipe, Author, and Date of Publication: