GET_POST仅返回第一个结果

时间:2020-03-20 作者:ilanb

我尝试获得如下\\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) }

1 个回复
SO网友:ilanb
// 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\'
                        GROUP BY post_id
                        HAVING distance < %f",
                        $earth_radius,
                        $latitude,
                        $longitude,
                        $latitude,
                        $radius
                        );

                        $sql = $wpdb->get_results( $querystrShop );
                        $sameCIParrayOfID = wp_list_pluck( $sql, \'post_id\' );

相关推荐

使用新的WP-Query()从循环中过滤后期格式;

嗨,我目前正在为我的博客构建一个主题。下面的代码指向最新的帖子(特色帖子)。因为这将有一个不同的风格比所有其他职位。然而我想过滤掉帖子格式:链接使用我在循环中定义的WP查询,因为它给我带来了更多的灵活性。我该怎么做呢? <?php $featured = new WP_Query(); $featured->query(\'showposts=1\'); ?> <?php while ($featured->have_post