문제

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

도움이 되었습니까?

해결책

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;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 wordpress.stackexchange
scroll top