目标是使用WooCommerce产品中的标签,列出WooCommerce产品下面的附件。如果我在以下位置手动输入标签,一切正常\'product_tag\'
, 但是当我尝试使用数组时$producttags
, 为什么不起作用?
add_action( \'woocommerce_after_single_product_summary\', \'precon_drawing_attachments\' );
function precon_drawing_attachments() {
$productterms = get_the_terms( $post->ID, \'product_tag\' );
$producttags = array();
foreach ( $productterms as $productterm ) {
$producttags[] = $productterm->name;
}
$args = array(
\'post_mime_type\' => \'application/pdf\',
\'post_type\' => \'attachment\',
\'product_tag\' => array( $producttags ),
\'posts_per_page\' => -1,
\'post_status\' => \'any\',
\'post_parent\' => null );
$attachments = get_posts( $args );
if ( $attachments ) {
echo \'<div class="drawings-list">\';
echo \'<ul>\';
foreach ( $attachments as $post ) {
echo \'<li class="drawing-li">\';
echo \'<img class="drawing-icon" src="\';
bloginfo( \'stylesheet_directory\' );
echo \'/images/Adobe_PDF_file_icon_32x32.png"\';
echo \' />\';
echo \'<span class="drawing-link">\';
echo the_attachment_link( $post->ID, false );
echo \'</span>\';
echo \'</li>\';
}
echo \'</ul></div>\';
}
}