Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 获取所有变体图像(附加变体图像)_Php_Wordpress_Plugins_Woocommerce - Fatal编程技术网

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加入。