2 回答

TA貢獻1772條經驗 獲得超8個贊
最后我發現,在顯示404頁面之前有一個鉤子,
因此,用于$wp_query->query['name']獲取搜索查詢文本,即 london 或 toronto。
然后使用我用谷歌地圖 API 檢查有效地點。一旦它有效,我就會重定向到具有該位置的搜索 url。我在帶有地理位置的主題正常搜索中找到了它。請在您的主題functions.php 中使用以下代碼。
在某些地方我使用了我的主題功能
fw_get_db_settings_option
在 myredirect_url 中使用您的主題正常搜索 url 和地理位置
add_filter('template_redirect', 'my_404_override' );
function my_404_override() {
global $wp_query;
$mysearch_location = $wp_query->query['name'];
$google_key = '';
if (function_exists('fw_get_db_settings_option')) {
$google_key = trim(fw_get_db_settings_option('google_key'));
}
$protocol = is_ssl() ? 'https' : 'http';
$place_detail = file_get_contents($protocol .'://maps.googleapis.com/maps/api/place/textsearch/json?query='.$mysearch_location.'&key='.$google_key);
$place_detail = json_decode($place_detail);
$formatted_address = $place_detail->results[0]->formatted_address;
$latitude = $place_detail->results[0]->geometry->location->lat;
$longitude = $place_detail->results[0]->geometry->location->lng;
if($place_detail->status=='OK'){
status_header( 200 );
$wp_query->is_404=false;
$myredirect_url = get_site_url() .'/find/?keyword=&geo='.$formatted_address.'&geo_distance=11&lat='.$latitude.'&long='.$longitude.'&location='.$formatted_address.'&category=';
wp_redirect( $myredirect_url );
exit;
}
}

TA貢獻1825條經驗 獲得超4個贊
手動方式只需將所有文件移動到服務器和數據庫到 phpmyadmin 新創建的數據庫。
之后,在您的數據庫主機的根 wp-config 文件中添加憑據,并添加
define( 'WP_HOME', 'http://example.com' ); define( 'WP_SITEURL', 'http://example.com' );
使用連接到您的主機的域名更新了 example.com。
到你的 wp-config 文件。
其他方式使用 Duplicator 插件來輕松遷移站點
如果要創建許多子站點,則需要在 word-press 中使用多站點網絡,這樣您就可以為不同的位置創建單獨的站點。
- 2 回答
- 0 關注
- 118 瀏覽
添加回答
舉報