我尝试获得如下\\u帖子:
$sql = $wpdb->get_results( $querystrShop );
// Create array of product ID
foreach ($sql as $prd)
{
$arraycip = array(
\'post_type\' => \'product\',
\'post_status\' => \'publish\',
\'posts_per_page\' => -1,
\'post__in\'=> array($prd->post_id),
\'fields\' => \'ids\'
);
}
$sameCIParrayOfID = get_posts($arraycip);
但它们只是第一个帖子:
$sql return 2产品$ArrayChip只有第一个产品
谢谢
编辑1
尝试另一种思考:
$html = urldecode( $_GET[\'product_search\'] );
//printf($html);
// Get the category ID from url
$catsearched = $_GET[\'product_cat\'];
//printf($catsearched);
$earth_radius = 6371;
// Get products of category with in range distance
$querystrShop = $wpdb->prepare("
SELECT productid
AS post_id,(%d * ACOS(COS(RADIANS(%s)) * COS(RADIANS(phiz_geo_location.latitude)) * COS(RADIANS(phiz_geo_location.longitude) - RADIANS(%s)) + SIN(RADIANS(%s)) * SIN(RADIANS(phiz_geo_location.latitude))))
AS distance, phiz_postmeta.meta_value
FROM phiz_geo_location
JOIN phiz_term_relationships ON phiz_geo_location.productid = phiz_term_relationships.object_id
LEFT JOIN phiz_postmeta ON phiz_geo_location.productid = phiz_postmeta.post_id
LEFT JOIN phiz_posts AS p ON phiz_postmeta.post_id = p.id
WHERE phiz_term_relationships.term_taxonomy_id IN ($catsearched)
AND p.post_title =\'".$html."\'
AND p.post_status = \'publish\'
HAVING distance < %f",
$earth_radius,
$latitude,
$longitude,
$latitude,
$radius
);
$sql = $wpdb->get_results( $querystrShop );
$productArrayShop = array();
foreach ($sql as $prd)
{
$productArrayShop[] = $prd->post_id;
}
$res = implode(",", $productArrayShop);
$arg = array(
\'post_type\' => \'product\',
\'post_status\' => \'publish\',
\'posts_per_page\' => -1,
\'post__in\'=> array($res),
\'fields\' => \'ids\'
);
$sameCIParrayOfID = get_posts($arg);
变量$sameCIParrayOfID只返回第一个产品,但变量$res返回2个产品
string(15) "2146031,2176394" array(1) { [0]=> int(2146031) }