Count custom post types with a specific meta value

1st. you need to add post_type to your query, then you need to filter meta_value with LIKE. Finaly, you need to add posts_per_page as -1 to get ALL posts.

$args = array(
    'post_type'=> 'books',
    'meta_query' => array(
                     array(
                        'key'     => 'book_type',
                        'value'   => 'Fiction',
                        'compare' => 'LIKE',
                    )
                ),
);
$query = new WP_Query($args);
$fiction = $query->found_posts;

Leave a Comment