doucaigai7176 2016-09-08 21:57
浏览 23

如何编写有效的wordpress插件,通过邮政编码使用用户输入进行搜索

I am trying to create my own word-press plugin which will allow a user to submit their postcode on a form, this will search a list of postcodes and select a correct area and then divert the user to the webpage with the appropriate area in the URL.

I am struggling to get this to work, and am also worried I may be taking an altogether ridiculous approach, and would appreciate (constructive) advice from somebody with more experience.

I have managed to get all of the postcode data corresponding to area in a table. This is roughly 2 million rows for reference. eg. WD4 5SH - Hartfordshire

The current approach I have tried is to create a plugin which is essentially the one function, it creates the postcode data into an array. It then takes the user input and finds the corresponding area. Finally it uses the header function to redirect to the appropriate URL.

I have tried to test this on instant wordpress, but it has come up with an error of the memory limit being reached. I could possibly try to increase the memory, but I am now worried that this is going to make the website really heavy, and maybe I should be using some sort of database.

To give you a general idea of my level I am moderately comfortable with scripting mostly in Perl and R but new to Wordpress.

My code is essentially:

Plugin:

<?php 
/** 
* Plugin Name: wordpress plugin 
**/ 
function Search_Area_function($post_code) {
$Postcodes = array( "AL1 1AG" => "1", "AL1 1AJ" => "2" );
$AreaKey = array( "1" => "Hertfordshire", "2" => "Bedfordshire");

/* Search array for the core post info, assign number simultaneously */

$currentAreaCode = array_search($post_code, $Postcodes);
$areafound = array_search($currentAreaCode, $AreaKey);

/* redirect to county page  */
header('Location: examplewebsite.com/'.$areafound);
}
?>

Form:

<form id="search" action="wordpress_plugin.php" method="get">
<div><input id="s" name="s" type="text" value="Postcode" />     <input   id="searchsubmit" type="submit" value="search" /></div>
</form>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 AT89C51控制8位八段数码管显示时钟。
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题