我认为问题是你把错误的论点传给了$attachments
查询,导致您无法在$attachments
查询
以下是您正在执行的操作:
$args = array(
\'post_status\' => \'inherit\',
\'numberposts\' => 0,
\'post__not_in\' => array_merge($do_not_duplicate,get_option( \'sticky_posts\' )),
\'post_type\' => \'attachment\',
);
$args[\'tax_query\'] = array(
array(
\'taxonomy\' => \'t-arte\',
\'terms\' => $term_id,
\'field\' => \'id\',
),
);
$attachments = get_posts( $args );
因此,您正在查询所有属于帖子类型的帖子
attachment
, 而不仅仅是连接到当前帖子的帖子在
$media_query
.
这是你如何循环的$media_query
:
foreach ($media_query as $media_query) :
(注意:格式错误。请尝试以下操作
foreach ( $media_query as $media ) :
相反。)
您需要将当前帖子的ID传递给$attachments
查询,作为post_parent
. 简单的可能是:
$attachments = get_posts( array(
\'post_status\' => \'inherit\',
\'post_type\' => \'attachment\',
\'post_parent\' => $media_query->ID
\'numberposts\' => 0
) );