Getting the maximum custom field value inside taxonomy term
-
Hi!
I’m building a site that lists products that have a custom field “value1”. So I have a custom post type ‘product’ and it has two taxonomies ‘brand’ and ‘model’.
When I’m in custom taxonomy archive page i would like to get the highest value1 in that taxonomy. I have found this code:
function max_meta_value(){ global $wpdb; $query = "SELECT max(cast(meta_value as unsigned)) FROM wp_postmeta WHERE meta_key='value1'"; $the_max = $wpdb->get_var($query); return $the_max; }
That gives me the highest value1 of all products. So how should i modify that to get the highest value1 of that taxonomy I am viewing?
I’m a novice in SQL queries and i have tried a lot of different commands there without any luck. So basically i would just need some help figuring out how to add some lines to that query so i can add it to my archive page template like this for exaple:
max_meta_value($brand,$model)
I appreciate all the help i can get! So if you know your way around the SQL query commands i would be more than happy to hear how it should be done ??
- The topic ‘Getting the maximum custom field value inside taxonomy term’ is closed to new replies.