سؤال

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