开发者

Wordpress - Custom field array of image ID's

I'm using the new wordpress custom post types and fields.

It's all working great, but for a custom image field (where I can select multiple images in one field), the value of this field when output is an array:

<?php
$field = get_post_meta($post->ID, "puma", false);
echo $field[0];
?>

This results in the following output (there are 3 images here):

180|177|174

These are clearly 开发者_Go百科the image ID's stored in the wp_posts table of the database.

However, before I go mad trying to do this manually via an SQL query (hack), I was wondering if there is a better and more native way in wordpress to get the value of these or the proper way to output these images?

Cheers, Michael.

EDIT:

Thanks to some help I got below, the final code for anybody who needs it is this:

<?php

    $field = get_post_meta($post->ID, "myImageField", false);
    $str = $field[0] . "|"; // add an extra pipe at the end to get ALL the items (kinda tricking it.
    $theIDarray = explode('|', $str, -1);

    foreach ($theIDarray as $value) {

        echo wp_get_attachment_image($value, "myCustomImageSize");

    }

?>

This works for a custom field with multiple image selections for the 'content-types-wordpress-plugin'. Hope it helps those in need!


I think below function can return image, if you pass image id as parameter :

echo wp_get_attachment_image($image_id)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜