Php 获取所有变体图像(附加变体图像)
我需要检索变体的所有图像,我可以使用Php 获取所有变体图像(附加变体图像),php,wordpress,plugins,woocommerce,Php,Wordpress,Plugins,Woocommerce,我需要检索变体的所有图像,我可以使用 $variation=wc\u get\u产品($variation\u id); $updated_image_id=$variation->get_image_id('edit'); 但是,如果我知道变体id,如何获得所有其他变体图像?您可以尝试此方法-但未经测试 $args = array( 'post_parent' => $variation_id, 'post_type' => 'attachment', '
$variation=wc\u get\u产品($variation\u id);
$updated_image_id=$variation->get_image_id('edit');
但是,如果我知道变体id,如何获得所有其他变体图像?您可以尝试此方法-但未经测试
$args = array(
'post_parent' => $variation_id,
'post_type' => 'attachment',
'post_mime_type' => 'image'
);
$images = get_children( $args );
if ( empty($images) ) {
// no attachments here
} else {
foreach ( $images as $attachment_id => $attachment ) {
//Do whatever here
echo wp_get_attachment_image( $attachment_id, 'full' );
}
}
这些变化有几个图像?还是要循环浏览变体?变体有多个图像。我想循环浏览单个变体的图像。请尝试使用
$variation->get_image_id('edit')
切换$variation->get_gallery_image_id()
应该为您提供图库中的图像ID数组。根据您的woocommerce版本,如果是旧版本,请使用$variation->get_gallery_attachment_ID()代码>库为空,图像在变体中。它们存储在数据库表wp_postemta中,键为“_wp_attached_file”,但使用它们自己的post id,我无法使用变体id加入。