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>