meta_query order_by meta_value_num does not like FLOAT numbers
-
Hello,
I am developing a complex theme, where users may sort posts based on a meta_key (which is a price).
My prices resemble this kind of values : “4,90”, “4,35”, “5,15”.
The piece of code i wrote works well with one exception : the sorting omits the value after the comma.
Writing this, i guess the problem here may be the following : prices are in french, not in english, so where you would use a dot in english, most european countries use a comma.
How would i be able to fix this without replacing every comma in my database ? Is there a possibility i could do a str_replace() while executing my code ?Here is my code :
<? if ($_GET['o'] == "price_desc") { $args = array( 'posts_per_page' => '9', 'cat' => $current, 'paged' => $paged, 'meta_key' => 'price', 'orderby' => 'meta_value_num', 'order'=>'DESC', ); } $myposts = new WP_Query($args); while ($myposts->have_posts()) : $myposts->the_post(); get_template_part('content_post'); endwhile; wp_reset_postdata(); ?>
$current is the current category id
Any help appreciated.
PS : My WP install is using fr_FR as WP_LANG.
- The topic ‘meta_query order_by meta_value_num does not like FLOAT numbers’ is closed to new replies.