我正在做一个项目
我们有x个帖子,1个赞助商(自定义元域),无限付费,无限免费帖子(这些都是帖子类型)
我们需要在顶部显示1个赞助商,无限制后付费,无限制后付费我们需要根据用户选择的区域的距离来订购所有产品
每篇文章都有存储在数据库中的位置
Question #1:
目前,我用3个不同的$参数进行了3个不同的查询:
$args_sponsored = array(
\'post_type\' => array(\'le_place\'),
\'posts_per_page\' => \'1\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'le_place_category\',
\'field\' => \'slug\',
\'terms\' => array($theCat)
)
),
\'meta_query\' => array(
array(
\'key\' => \'entry_type\',
\'value\' => \'sponsored\',
)
)
);
$args_paid = array(
\'post_type\' => array(\'le_place\'),
\'posts_per_page\' => -1,
\'order\' => \'DESC\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'le_place_category\',
\'field\' => \'slug\',
\'terms\' => array($theCat)
)
),
\'meta_query\' => array(
array(
\'key\' => \'entry_type\',
\'value\' => array(\'paid\'),
)
)
);
$args_free = array(
\'post_type\' => array(\'le_place\'),
\'posts_per_page\' => -1,
\'order\' => \'DESC\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'le_place_category\',
\'field\' => \'slug\',
\'terms\' => array($theCat)
)
),
\'meta_query\' => array(
array(
\'key\' => \'entry_type\',
\'value\' => array(\'free\'),
)
)
);
and not sure this affect performance! is that a wrong method?
Question #2:在获得所有帖子后,如何按距离对它们进行排序,然后显示它们?
sortByDistance($postsPaid); // how can I get custom fields of post objects?
$postsPaid = $queryPaid->get_posts();
sortByDistance($postsPaid); // how can I get custom fields of post objects?
$placeLocation= get_field(\'location\');
$longPlace =$placeLocation[\'lng\'];
$latPlace = $placeLocation[\'lat\'];
function getDistance($lat2, $long2, $lat1, $long1) {
$R = 6378137; // Earth’s mean radius in meter
$dLat = rad($lat2 - $lat1);
$dLong = rad($long2 - $long1);
$a = sin($dLat / 2) * sin($dLat / 2) +
cos(rad($lat1)) * cos(rad($lat2)) *
sin($dLong / 2) * sin($dLong / 2);
$c = 2 * atan2(sqrt($a), sqrt(1 - $a));
$d = $R * $c; // in meter
return intval((ceil($d) / 1000) * 0.621371); // returns the distance in Miles
};