使用GET_ANNEXT_POST获取自定义帖子类型信息

时间:2012-04-16 作者:Romes

这是我现在如何从自定义帖子类型中获取图像的一个示例,使用query_posts();

// query_posts stuff made up here.
$my_array = get_custom_field(\'image:to_array\', \'to_image_array\'); 
// $my_array is now all my images from that post.
我要做的是使用get\\u nextigation\\u post()从自定义post类型中拉出一个图像。当我打印出相邻帖子的信息时,我看不到任何有助于从此帖子类型中提取图像的内容。这是相邻帖子的打印内容。

(
    [ID] => 185
    [post_author] => 1
    [post_date] => 2012-04-11 18:51:22
    [post_date_gmt] => 2012-04-11 18:51:22
    [post_content] => content
    [post_title] => the title
    [post_excerpt] => 
    [post_status] => publish
    [comment_status] => open
    [ping_status] => closed
    [post_password] => 
    [post_name] => the-title
    [to_ping] => 
    [pinged] => 
    [post_modified] => 2012-04-12 17:37:49
    [post_modified_gmt] => 2012-04-12 17:37:49
    [post_content_filtered] => 
    [post_parent] => 0
    [guid] => http://thewebsite.com/?post_type=photo_group&p=185
    [menu_order] => 0
    [post_type] => photo_group
    [post_mime_type] => 
    [comment_count] => 0
)
有没有办法用这种方式拉出我的自定义帖子类型的图片?

2 个回复
SO网友:Tom J Nowell

get_custom_field 不是标准的wordpress函数,除非提供源代码,否则我们无法帮助您使用它。

但我可以告诉你,它不是从post对象获取数据,而是从post meta获取数据。

e、 g。

$value = get_post_meta($post->ID,\'key name\',true); // where true indicates there is only a single key value pair of \'key name\'

SO网友:IFightCode

get_post_meta 也可以帮助你。使用这种方式

global $wp_query;

$postid = $wp_query->post->ID;

echo get_post_meta($postid, \'key\', true);

结束

相关推荐