Create efficient WordPress meta query

I'm working with WordPress with custom fields and trying to convert a query which was initially written for pjjtextbase (textfile database) to search a csv file for matching properties for rent/sale. The code works well but is quite inefficient.

The code from the original progammer is

/***** These values needed for select box *****/

$locations = ptb_listUnique($info, 'Property_Location');

$property_type = ptb_listUnique($info, 'Property_Type');

$property_buy_rent = ptb_listUnique($info, 'Buy_Rent');

//check property

$query = Array();

if(!empty($_GET['location'])) {

$query[] = "'Property_Location' == '".$_GET['location']."'";


if(!empty($_GET['type'])) {

$query[] = "'Property_Type' == '".$_GET['type']."'";


if(!empty($_GET['buyrent'])) {

$query[] = "'Buy_Rent' == '".$_GET['buyrent']."'";


//check price

if(empty($_GET['buyrent']) || $_GET['buyrent']=="Buy"){

if(!empty($_GET["min_val_buy"]) && is_numeric($_GET["min_val_buy"])){

$min_val_buy = $_GET["min_val_buy"];


if(!empty($_GET["max_val_buy"]) && is_numeric($_GET["max_val_buy"])){

$max_val_buy = $_GET["max_val_buy"];


$min_val_buy = min($_GET["min_val_buy"], $_GET["max_val_buy"]);

$max_val_buy = max($_GET["min_val_buy"], $_GET["max_val_buy"]);

$query[] = "'Price_Rent' >= '".$min_val_buy."'";

$query[] = "'Price_Rent' <= '".$max_val_buy."'";


if(!empty($_GET["min_val_rent"]) && is_numeric($_GET["min_val_rent"])){

$min_val = $_GET["min_val_rent"];


if(!empty($_GET["max_val_rent"]) && is_numeric($_GET["max_val_rent"])){

$max_val = $_GET["max_val_rent"];


$min_val_rent = min($_GET["min_val_rent"], $_GET["max_val_rent"]);

$max_val_rent = max($_GET["min_val_rent"], $_GET["max_val_rent"]);

$query[] = "'Price_Rent' >= '".$min_val_rent."'";

$query[] = "'Price_Rent' <= '".$max_val_rent."'";


//check bedrooms

if(!empty($_GET["room_no_min"]) && is_numeric($_GET["room_no_min"])){

$room_min_val = $_GET["room_no_min"];


if(!empty($_GET["room_no_max"]) && is_numeric($_GET["room_no_max"])){

$room_max_val = $_GET["room_no_max"];


$room_min_val = min($_GET["room_no_min"], $_GET["room_no_max"]);

$room_max_val = max($_GET["room_no_min"], $_GET["room_no_max"]);

$query[] = "'No_Bedrooms' >= '".$room_min_val."'";

$query[] = "'No_Bedrooms' <= '".$room_max_val."'";

//Now build the query to search

$query = implode(' AND ', $query);

I would like this to be converted into a WordPress meta array that fits into this code

function propertysearch ()


$location = preg_replace('/^-|-$|[^-a-zA-Z0-9]/', '', $_GET['location']);

$type = preg_replace('/^-|-$|[^-a-zA-Z0-9]/', '', $_GET['type']);

$buyrent = preg_replace('/^-|-$|[^-a-zA-Z0-9]/', '', $_GET['buyrent']);

$min_val =preg_replace('/[^0-9]/', '', $_GET['min_val']);

$room_no_min = preg_replace('/[^0-9]/', '', $_GET['room_no_min']);

// This replaces characters in the input string if need be for security reasons


if(($results == 0) || ($results == false) || ($results == NULL)) :

echo '<p>Sorry, there seems to be no results for your request.</p>';

$results = NULL;

return $results;

else :

return $results;


} // End of my search

Taidot: CSS, HTML, PHP, WordPress

Näytä lisää: string matching in c, search string in array, matching string, php, wordpress, wordpress template, wordpress development, efficient string matching

Tietoa työnantajasta:
( 31 arvostelua ) London, United Kingdom

Projektin tunnus: #9133750

Myönnetty käyttäjälle:


Hi ) We are ready to discuss your project. Not the time-wasters ) Please, let us know the details of your project if you will be interested in us! Thank you, Alscon team )

£40 GBP 1 päivässä
(73 Arvostelua)

12 freelanceria on tarjonnut keskimäärin %project_bid_stats_avg_sub_26% %project_currencyDetails_sign_sub_27% tähän työhön


Предложение еще не подано

£32 GBP 1 päivässä
(444 arvostelua)

I am willing to work with you I am not saying that i am the best but my coding skills show you that i em the best i am highly interested in this job. Skills: Laravel 5 PHP/MYSQL Word Press Code Igniter JS/Jquer Lisää

£105 GBP 1 päivässä
(224 arvostelua)

I can do it for you, I've experience 5 years with wordpress , new + custom PLG , themes and more... Now, I believe I can do it good for you! Would happy if work with you !

£37 GBP 1 päivässä
(74 arvostelua)

Hello Sir I have gone through the project specification. I have prior experience with similar types of websites. I will use my skill to make you happy. I am a developer with 4 yrs of experience with wordpress, wo Lisää

£36 GBP 1 päivässä
(156 arvostelua)

Got your requirement and ready to work with you. I am pro in wordpress and active member of I can assure you quality work on time. Please explain your work in detail. I can start immediate. Have you Lisää

£27 GBP 1 päivässä
(80 arvostelua)

Hello Sir, WORDPRESS expert here. please check my recent work in WORDPRESS [login to view URL] [login to view URL] [login to view URL] [login to view URL] http://webxcelle Lisää

£44 GBP 2 päivässä
(79 arvostelua)

Hello, woo pro here I go get your stuff done for you professionally. I'll do your this task..If you want so please me message Please visit our work: [login to view URL] [login to view URL] [login to view URL] looking forwa Lisää

£45 GBP 0 päivässä
(93 arvostelua)

Hello. Thanks for the opportunity. I have gone through your project details and am glad to offer our white labelling services to you. i can continue on your website. i have 4 year experienced with wordpress , m Lisää

£23 GBP 1 päivässä
(44 arvostelua)

We have solution for you and we can link these query in WordPress using get_post_meta()function we need to write function for this. Let us have words on this.

£33 GBP 2 päivässä
(1 arvostelu)

Hey! Yes, we are ready to help. Everything you require we can make at its best. And we can convert query which was initially written. Maybe we are new on Freelancer but we are pretty long time on this market an Lisää

£10 GBP 3 päivässä
(0 arvostelua)

Hello we are a young Ukrainian team. Consist with 10 developers 2 PM and designer, QA We Develop web [login to view URL] have experience in developing websites. Contact Us.

£28 GBP 3 päivässä
(0 arvostelua)