You must be logged in to post a comment.

  1. The ID? just change the select from meta_value to id perhaps

  2. Hello,

    Thank you for your query !
    Me I am looking for not the name of the meat key but the number of the meta key.

    I explain me..

    I have a custom post type listings....
    I have 2 cities (Post Meta) actualy who have some post type.
    Echo my query

    global $wpdb;
    $metakey = 'ville';
    $results = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = %s ORDER BY meta_value ASC", $metakey ) );
    foreach ($results as $result){
    $subcount = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s", $metakey, $result ) );
    echo "$result";

    The result is St Boniface and Trois-Rivières. Well the result is correct because i have two cites where i have post type published.

    The quesion is it possible to have a number = 2, no this result = St Boniface Trois-Rivières..

    Have you an idea ?

    Thank You