Count pod entries in a specific pod (by meta_value)
-
Hello,
I am trying to retrieve the number of Pods posts in a certain pods with a specific “meta_value”. The “where” field of the Pods block “list items” works perfectly and I am trying to reproduce a similar result via PHP to only retrieve the number of posts BUT not actually display them…
The following php block gives the number of posts in the “book” pod:
<?php $count_posts = wp_count_posts( 'book' )->publish; echo $count_posts; ?>
However, if I want to only get the number of posts where the “genre” field is set to value “Fiction”, I tried this code:
<?php $posts = get_posts(array( 'post_type' => 'book', 'meta_key' => 'genres', 'meta_value' => 'Fiction' )); echo count($posts); ?>
However WP is returning “5” when it should return much more…. This seems to be normal as “get_posts” is apparently “coded” to return 5 unless some options are set. I tried to add:
'posts_per_page' => -1,
and
'nopaging' => true,
but WP is returning:
Parse error: syntax error, unexpected ''nopaging'' (T_CONSTANT_ENCAPSED_STRING), expecting ')' in /mnt/data/wordpress-data/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(97) : eval()'d code on line 6
What am I missing here?
- The topic ‘Count pod entries in a specific pod (by meta_value)’ is closed to new replies.