meta_query works locally but not on live server

I’m filtering posts by author’s last name initials. On my local server, the query runs beautifully, but when I push live, it doesn’t. It doesn’t find anything. Does it have anything to do with the way I’m escaping the custom field value?

$author = get_query_var('author-initials');

if (!empty($author)) {

    $initials = explode('-', $author);
    $value = array();

    foreach($initials as $initial) {
        $value[] = strtolower($initial);
        $value[] = strtoupper($initial);
    }

    $meta_query[] = array(
        'key' => 'whitepaper_author',
        'value' => "\s[" . implode('', $value) . "]\w+$",
        'compare' => 'REGEXP'
    );
}

if (count($meta_query) > 1) {
    $meta_query['relation'] = 'OR';
}

$query->set('meta_query', $meta_query);

1 Answer
1

Please try using (blank space) instead of \s and . instead of \w

For further details on supported operators and characters please check this link: https://dev.mysql.com/doc/refman/5.7/en/regexp.html

Leave a Comment