我需要从自定义字段数组中获取产品ID,我使用此代码查找具有相同自定义字段的所有产品,删除所有重复的自定义字段值后,我需要检索所有自定义字段的产品ID:
<?php
// Get all product cip by category
$product_args = array(
\'post_type\' => \'product\',
\'no_found_rows\' => true, // Skips SQL to count rows - a speed improvement.
\'post_status\' => \'publish\',
\'ignore_sticky_posts\' => true, // Don\'t move sticky posts to top - a speed improvement.
\'posts_per_page\' => -1,
\'fields\' => \'ids\', // Only return product IDs
);
if (!empty($str_ArrayChild))
{
$product_args[\'tax_query\'] = array(
array(
\'taxonomy\' => \'product_cat\',
\'field\' => \'id\',
\'terms\' => $str_ArrayChild,
\'operator\' => \'IN\',
));
}
$products = get_posts($product_args);
// Search CIP by product ID
foreach ( $products as $id )
{
$cip = $product_obj[\'product_cip\']=get_post_meta($id,\'product_cip\');
//echo \'Cip = \'.$cip[0].\', \';
$arrayCip[] = $cip[0];
}
echo \'<b>TotalNumberOfCIP = \'.count($arrayCip).\'</b>\';
// Remove same cip
$result = array_unique($arrayCip);
//print_r($result);
echo \'<b>TotalNumberOfUniqueCIP = \'.count($result).\'</b>\';
// trace Unique Cip list
/*foreach ($arrayCip as $v)
{
echo $v;
}
这里我需要找到$arrayCip
(名为customfieldproduct_cip
)