获取附件自定义字段值

时间:2014-10-28 13:06:34

标签: php wordpress

我在WordPress的附件表单中有一个自定义字段。

我正在将此值存储在此&现在想在公共端显示价值。

通过这个http://codex.wordpress.org/Function_Reference/wp_get_attachment_metadata,这应该会有所帮助,但不会: <?php wp_get_attachment_metadata( $attachment_id, $unfiltered ); ?>

有人可以帮忙吗?

谢谢

1 个答案:

答案 0 :(得分:1)

wp_get_attachment_metadata结果是:

Array
(
    [width] =>
    [height] =>
    [file] =>
    [sizes] => Array
        (
            [thumbnail] => Array
                (
                    [file] =>
                    [width] =>
                    [height] =>
                    [mime-type] =>
                )

            [medium] => Array
                (
                    [file] =>
                    [width] =>
                    [height] => 
                    [mime-type] => 
                )

        )

    [image_meta] => Array
        (
            [aperture] => 
            [credit] => 
            [camera] => 
            [caption] => 
            [created_timestamp] => 
            [copyright] => 
            [focal_length] => 
            [iso] => 
            [shutter_speed] => 
            [title] => 
        )

)

所以,这是附件数据。但是你想获得自定义字段。你可以使用相同的帖子:

get_post_meta($post->ID, 'your_field_name', true);

所有这些都可以在attachment.php中找到。在附件页面中,$ post是附件帖子,因此不是父帖子。