WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Count posts with meta_key LIKE (3 posts)

  1. csseur3
    Member
    Posted 5 years ago #

    Hello,

    this is my query:

    $test_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->postmeta WHERE meta_key LIKE '%salon%'", $meta_key));

    I have many posts with meta_key "salon_irc" and "salon_jabber", so, my query count only the posts with "salon_jabber" meta_key :( why?

    bye

  2. frank8265
    Member
    Posted 5 years ago #

    Hi csseur3,

    Can you tell me how you resolved this?
    I've got the same sort of problem. :-/

    Thanks.

    Frank

  3. csseur3
    Member
    Posted 5 years ago #

    $stat_all_chat = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts a WHERE EXISTS (SELECT meta_id FROM $wpdb->postmeta WHERE post_id = a.ID AND meta_key in ( 'salon_irc', 'salon_jabber'))");

    :)

Topic Closed

This topic has been closed to new replies.

About this Topic