Link the retrieved custom field values to its respective posts
You achieve this by modifying your code as following and using get_results function instead of get_col function. <?php function get_meta_values( $key = ”, $type=”post”, $status=”publish” ) { global $wpdb; if( empty( $key ) ) return; $r = $wpdb->get_results( $wpdb->prepare( ” SELECT pm.meta_value, p.ID FROM {$wpdb->postmeta} pm LEFT JOIN {$wpdb->posts} p ON p.ID = pm.post_id WHERE … Read more