Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How can i get the count for published post from my custom post type , from my taxonomy.

I have Custom Post Type : trailers, Taxonomy : trailere-noi

<?php 

$items = get_posts( array(
    'post_type'   => 'trailers',
    'numberposts' => -1,
    'taxonomy'    => 'trailere-noi',
    ));

$count =  count( $posts );
echo $count;


?>

I use this code it conunt for how posts are display.. how can get the count for all posts in that taxonomy?


Response:

<?php 
$related_posts = get_field( 'subtitrare_film' );
$count =  count( $related_posts );
echo $count;
?>

Subtitrare_film - is the relathionship field (INFO :http://www.advancedcustomfields.com/docs/field-types/relationship/) This code Retrive me the field counting number, but the problem is: if there is nothing atached to that Custom Field ( Relationship fild) it retrive me number 1 , i want to display 0 ( if there is nothing atachhed.)

share|improve this question
    
... you need to be counting $items not $posts. $count = count($items); –  s_ha_dum Jan 12 '13 at 15:47

2 Answers 2

i see another thing in your code, your count() function is counting something that does't exists, the variable $posts, so please try with $items->post_count;

another option is :

global $wp_query
$items = get_posts( array(
    'post_type'   => 'trailers',
    'numberposts' => -1,
    'taxonomy'    => 'trailere-noi',
    ));

echo $wp_query->found_posts

$wp_query should return the last query and since get_posts() works with wp_query this solution should work

share|improve this answer

try something like this:

$items = get_posts( array(
    'post_type'   => 'trailers',
    'numberposts' => -1,
    'taxonomy'    => 'trailere-noi',
    ));

echo $posts->post_count;
share|improve this answer
    
nope, is not retriving... –  Batman Jan 10 '13 at 22:24
    
Please explain why that could solve the problem. –  toscho Jan 11 '13 at 0:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.