List of users based on usermeta

  • Author
  • #531995


    Hello everyone,

    I’ve added to my wordpress website extra fields to the user profile. (meta_key= President, meta_value=on of off)

    I try to list the users of my wordpress website where Predisent = On and sorted by last name.

    A first try:

    $Query = $wpdb->get_col(“SELECT user_id FROM $wpdb->usermeta WHERE meta_key = ‘predisent’ AND meta_value =’on’.

    Filter is ok, but i don’t know how to order by last name

    A second try:

    $Query = $wpdb->get_col(“SELECT user_id FROM $wpdb->usermeta WHERE $wpdb->usermeta.meta_key = ‘last_name’ ORDER BY $wpdb->usermeta.meta_value ASC”

    This time, order is good… but no more filter (of course)

    Is there someone here that can help me?

    Thank you very much.



    You did not specify a blog address or reason for posting when you created this topic.

    This support forum is for blogs hosted at If your question is about a self-hosted WordPress blog then you’ll find help at the forums.

    If you don’t understand the difference between and, you may find this information helpful.

    If you forgot to include a link to your blog, you can reply and include it below. It’ll help people to answer your question.

    This is an automated message.

The topic ‘List of users based on usermeta’ is closed to new replies.