Searching for posts with custom data in a numeric range
-
Based upon this:
resolved postI’m stuck at the same problem, but my meta value starts with a currency sign. However, substring helped in this case, but now I encounter another problem -> the value in the meta_key is written like: $2.000 !
Using this<?php // Define the function that will create the join string function mam_custom_field_range($keyname='',$min=false,$max=false) { global $mam_global_join,$wpdb; if ($keyname && ($min !== false || $max !== false)) { $mam_global_join = " JOIN $wpdb->postmeta acfr_$keyname ON ( $wpdb->posts.ID = acfr_$keyname.post_id AND acfr_$keyname.meta_key = '$keyname'"; if ($min !== false) $mam_global_join .= " AND acfr_$keyname.meta_value >= $min"; if ($max !== false) $mam_global_join .= " AND acfr_$keyname.meta_value <= $max"; $mam_global_join .= ')'; } } // Define the join filter function function mam_posts_join ($join) { global $mam_global_join; if ($mam_global_join) $join .= $mam_global_join; return $join; } // Add the filter to the hooks add_filter('posts_join','mam_posts_join'); ?>
The query treats 2.000 as 2… how do I solve this ?
thanks in advance…
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Searching for posts with custom data in a numeric range’ is closed to new replies.