Support

Account

Home Forums General Issues Count completed custom post types by a particular field. Reply To: Count completed custom post types by a particular field.

  • There’s a missing comma in the code I provided. I don’t always test all the code I post because it’s meant as an example, sometimes typos slip in. I generally assume that most people can do basic code debugging.

    
    $args = array(
      'post_type' => 'your-post-type',
      'post_per_page' => -1, // get them all
      'post_status' => 'publish', // or whatever status your looking for
      'meta_query' => array(
        array(
          'key' => 'your-field-name',
          'compare' => 'EXISTS'
        )
      )
    )
    $query = new WP_Query($args);
    $post_count = count($query->posts);