Hi everyone. I have a site with a custom post type, and that custom post type has a custom field (text field). I want to create a dropdown list of all the different values entered into this field, but not repeating any values. So for example let's say three custom items existed and the following values were entered into the custom field:
I would like my drop down list to give only two options: 'Cat' and 'Dog'.
At the moment I am using the following code to get the values:
$pets= $wpdb->get_col("SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = 'pets' ORDER BY meta_value" ); $pets= array_unique($pets);
It works, but it's incredibly slow. I do have thousands of records in the database, so it could just be that, and I won't be able to speed it up - but I was wondering if there's a better way of achieving what I'm after?