我在这里发现了类似的问题,但我无法修改答案,仅从某个帖子类型获取图像,因为这些示例中的帖子类型是“附件”,而不是自定义帖子类型的名称。
有没有一种方法也可以声明自定义post类型参数?
我在这里发现了类似的问题,但我无法修改答案,仅从某个帖子类型获取图像,因为这些示例中的帖子类型是“附件”,而不是自定义帖子类型的名称。
有没有一种方法也可以声明自定义post类型参数?
在模板中尝试此代码。
$query = new WP_Query( array( \'post_type\' => \'custom-post\', \'posts_per_page\' => -1 ) );
if( $query->have_posts() ){
while($query->have_posts()){
$query->the_post();
$image_query = new WP_Query( array( \'post_type\' => \'attachment\', \'post_status\' => \'inherit\', \'post_mime_type\' => \'image\', \'posts_per_page\' => -1, \'post_parent\' => get_the_ID() ) );
while( $image_query->have_posts() ) {
$image_query->the_post();
echo wp_get_attachment_image( get_the_ID() );
}
}
}
更换custom-post
使用自定义帖子类型。我正在使用Attachments 插件,但我相信这个问题适用于常规媒体库。我想做的是有一个“附件”(元数据、标题、标题),但没有与之关联的图像。原因是,我想将附件视为“项目项”,可以是图像或文本块。这可能吗?