Pergunta

How should I use posts_where to change meta_value from a string to integer?

Foi útil?

Solução

Try this:

add_filter('posts_where', 'unquote_numeric_meta_value', 10, 2);

function unquote_numeric_meta_value($where, $args) {

    $value = isset($args->query_vars['meta_value']) ? $args->query_vars['meta_value'] : false;

    if(is_numeric($value))
        $where = str_replace("'{$value}'", $value, $where);

    return $where;
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a wordpress.stackexchange
scroll top