所以我找到了这篇帖子:Find the post an attachment is attached to 实施了Chip的建议但结果很奇怪。我正在尝试提取特定图像所附帖子的标题。这是我的问题:
<?php
$args = array(
\'post_type\' => \'attachment\',
\'posts_per_page\' => -1,
\'post_status\' => \'any\',
\'post_parent\' => null,
\'tax_query\' => array(
array(
\'taxonomy\' => \'post_tag\',
\'field\' => \'slug\',
\'terms\' => \'logo\'
)
)
);
$attachments = get_posts( $args );
foreach ( $attachments as $image ) {
// Get the parent post ID
$parent_id = $image->post_parent;
// Get the parent post Title
$parent_title = get_the_title( $parent_id );
// Get the parent post permalink
$parent_permalink = get_permalink( $parent_id );
}
if ( $attachments ) {
foreach ( $attachments as $post ) {
$logoimg = wp_get_attachment_image($post->ID, \'Work Gallery\');
这是我所说的标题:echo \' \' . $parent_title . \' \';
这种类型的作品,但它是输出一个职位的标题,特别是对所有的图片上的页面。有没有想过为什么它不会动态地拾取每个与帖子标题相关的图像?
谢谢