• Resolved csseur3

    (@csseur3)


    Hello,

    I try to count the number of posts which have two specific fields:

    <?php
          $test_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts a WHERE EXISTS (SELECT meta_id FROM $wpdb->postmeta WHERE post_id = a.ID AND meta_key = 'blablabla') AND EXISTS (SELECT meta_id FROM $wpdb->postmeta WHERE post_id = a.ID AND meta_key = 'test'", $meta_key));
          echo '' . $test_count . '';
          ?>

    but nothing appears (and there is no error) :/

  • The topic ‘Count number of posts with two perso fields’ is closed to new replies.