ThanksUPDATE:
This is the code that Im working with. I couldn't find any reliable solutions to implement REGEXP. Basically, what this should do, in theory, is use the php preg_replace
function to remove/replace any special characters in the string and query the new clean string, that will then be used in the query's argument. Here it is:
*The initial value of the variable are submitted through a milsimple html form (not included).
if(isset($_POST['providername'])) {
$providername = $_POST['providername'];
if (preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $providername))
{
$clean = $providername;
// Replace other special chars
$specialCharacters = array(
',' => '',
'&' => 'and',
'@' => 'at',
'.' => '',
'+' => '',
'=' => '',
'/' => '',
'*' => '',
'!' => '',
'(' => '',
')' => '',
'$' => '',
'#' => '',
'%' => '',
'\'' => '',
'_' => '',
'^' => '',
'-' => ''
);
while (list($character, $replacement) = each($specialCharacters)) {
$clean = str_replace($character, '-' . $replacement . '-', $clean);
}
// Remove all remaining other unknown characters
$clean = preg_replace('/[^a-zA-Z0-9\-]/', ' ', $clean);
$clean = preg_replace('/^[\-]+/', '', $clean);
$clean = preg_replace('/[\-]+$/', '', $clean);
$clean = preg_replace('/[\-]{2,}/', '', $clean);
if (preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $providername)) {
$providername = $clean;
} else {
$providername = $_POST['providername'];
}
}
}
if(isset($_POST['providerloc'])) {
$provider_location = $_POST['providerloc'];
}
This is the multi array argument:
$args = array(
'count_total' => true,
'role' => 'subscriber',
'offset' => 8,
'number' => 8,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'jabber',
'value' => $provider_location,
'compare' => 'LIKE'
) ,
array(
'key' => 'keywordcontent',
'value' => $providername,
'compare' => 'LIKE'
)
)
);
After testing this solution, I get no results when trying to search for the "clean" outputted value.
For example:
If...
$value = "G-P's Workin' Barn";
After applying preg_replace
, the output will be...
GPs Workin Barn
Now...if I search for "GPs Workin Barn" (the output value), I get no results. But when I search for "G-P's Workin' Barn" (the original value), it shows the result for that term. So it seems that the query isn't able to process the output value. As I thought, this makes sense because the query is searching against stored values in the database...There should be a way for the query to interpret/translate the output value and compare it against the stored value. After searching online, the closest solution that relates to what I need is the post_where filter for posts [credit @Rarst]. There doesn't seem to be a similar filter for users. Even so, I need a way to search using REGEXP against actual variable values.
Any thoughts or solutions? Thanks