I have the problem that my client is using a theme which stores options of items
in a serialized way in the post_meta
table.
I already found out that this is not the best way to save values especially if you want to query over them later, but so far I cannot change that fact.
I tried to query it with the REGEXP
compare option of the meta_query()
function.
$metaquery['meta_query'] = array(
'key' => '_ait-dir-item',
'value' => '*\"guestcount\";s:[0-9]+:\"'.$_GET['guestcount'].'\".*',
'compare' => 'REGEXP'
);
$query->set('meta_query',$metaquery);
So I can find the items with the exact geustcount of the user's input.
But I would like to find all items with guestcount >= input
.
How would that be possible?
UPDATE
I have tried it now with checking the number for a range with regex (while the regex is beeing created before)
$gc = (string)$_GET['guestcount']; //gc...guestcount
$input_regex = $gc[0];
for($i=1;$i<strlen($gc); $i++){
$input_regex .= "[".$gc[$i]."-9]";
}
$compare_regex = '|[2-9][0-9]{2}|[1-9][0-9]{3}|1[0-9]{4}|20000';
the max value of the range is always 20.000
.
Well ... I dont get any results with this... can anybody see a bug in it?
This was for the input = 150
:
'value' => '*\"guestcount\";s:[0-9]+:\"\b(1|[5-9][0-9]{2}|[1-9][0-9]{3}|1[0-9]{4}|20000)\b\".*
'
Update
I cleaned up the regex and removed th \b
and the .
and *
and stuff... now it seems, that I find alle items, where a guestcount is entered ... i.e. input=300
I also found one with 250 guestcount
...
'value' => '\"guestcount\";s:[0-9]+:\"(1|[5-9][0-9]{2}|[1-9][0-9]{3}|1[0-9]{4}|20000)\"
'
$compare
regex, I also had to use the first$gc[0]+1
value (exception for9
). Shell I post it as an answer?