【发布时间】:2015-08-31 04:24:38
【问题描述】:
我正在尝试在我的 Wordpress php 代码中获取附加/插入的图像,该代码已插入到管理界面的测试帖子中。我点击了“添加媒体”按钮并上传了我的图片并更新了帖子(front-page 是自定义帖子类型)。
(我点击了这个按钮):
但是,我似乎无法终生检索与该帖子相关的图片。如果我设置Feature Image(缩略图),我可以得到它,但不能插入图像。这是我尝试过的:
循环遍历附件(运气不好):
$attachments = query_posts(
array(
'post_type' => 'front-page', // only get "attachment" type posts
'post_parent' => $post->ID, // only get attachments for current post/page
'posts_per_page' => -1 // get all attachments
)
);
foreach($attachments as $attachment) {
echo get_the_ID();
echo wp_get_attachment_image( $attachment->ID, 'full' );
}
wp_attached_image(post ID)(运气不好):
wp_get_attachment_image( $post->ID );
得到所有帖子(运气不好):
<?php
$args = array(
'post_type' => 'front-page',
'post_mime_type' => 'image',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID
);
$attached_images = get_posts( $args );
echo $attached_images[0];
?>
获取帖子图库图片(不走运)
get_post_gallery_images( $post->ID );
我真的很困惑为什么我无法检索图像。我已经用尽了几乎所有可以在网上找到的建议,并且想知道它是否与我的自定义帖子类型有关还是什么?任何帮助将不胜感激。
【问题讨论】:
标签: php html wordpress image underscores-wp