Get Unique Post Meta Values From Meta Key

[php]
<?php
/* Don’t include the opening PHP tag*/

* @param string $key Post Meta Key.
*
* @param string $type Post Type. Default is post. You can pass custom post type here.
*
* @param string $status Post Status like Publish, draft, future etc. default is publish
*
* @return array
*/

function get_unique_post_meta_values( $key = ”, $type = ‘post’, $status = ‘publish’ ) {
global $wpdb;
if( empty( $key ) )
return;
$res = $wpdb->get_col( $wpdb->prepare( "
SELECT DISTINCT pm.meta_value FROM {$wpdb->postmeta} pm
LEFT JOIN {$wpdb->posts} p ON p.ID = pm.post_id
WHERE pm.meta_key = ‘%s’
AND p.post_status = ‘%s’
AND p.post_type = ‘%s’
", $key, $status, $type ) );
return $res;
}
[/php]
This is how you:

Get Unique Post Meta Values From Meta Key

The Default is post. You can pass custom post type too.

You can check this example url BankDirectVip how I Get Unique Post Meta Values From Meta Key as a select element to filter the results.

Get Unique Post Meta Values From Meta Key

Checkout some common problems.

How to make a custom widget area in wordpress?
How to Add Page Slug in Body Class of your WordPress Theme ?
How to make scroll to top ?
Media upload default linking (change the attachment link to none in WordPress)