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.

i have a get_terms which loads correctly.
inside of it i have used get_posts. then using get posts i am
trying to get each post tags (and count <= not currently inside this script)

<?php
    $categories = get_terms( 'blogs_cat', array(
        'type'                     => 'blogs',
        'orderby'                  => 'name',
        'order'                    => 'ASC',
        'hide_empty'               => 0,
        'exclude'                  => '1',
        'number'                   => '1000',
        'pad_counts'               => true 
        )
    ); 

    echo '<div class="clientList">';
    echo '<ul>';
    foreach ($categories as $category) {

        $colorClass = '';

        // COUNT NUMBER OF TAGS AKA: PUBLISHED / NOT PUBLISHED ARTICLES
        $termID = $category->term_id;
        $taxonomyNAME = $category->taxonomy;
        $termSLUG = $category->slug;

        $items = get_posts( array(
            'post_type'   => 'blogs',
            'numberposts' => -1,
            'taxonomy'    => $taxonomyNAME,
            'term'        => $termSLUG
            ) );
        $totalPostsCount =  count( $items );

        // WHEN PRINT_R EACH ITEM RETURNS UNIQE ID
        foreach ($items as $item) {
            $posttags = get_the_tags($item->term_id);
            if ($posttags) {
              foreach($posttags as $tag) {
                // HERE I GET SAME TAG NAME FOR ALL TAGS ACROSS POSTS (IN THIS CASE ITEMS)
                echo $tag->name; 
              } 
            }
        }


        //print_r($category);
        echo '<li class="'.$listClass.'"><div class="clientContainer"><a href="' . get_term_link($category->slug, 'blogs_cat') . '" title="' . sprintf( __( "All Articles By: %s" ), $category->name ) . '" ' . '>' . $category->name.'</a><div class="articleCount '.$colorClass.'"> ('.$totalPostsCount.' / p'.$publishedArticle.') </div></div></li>';
    }
    echo '</ul>';
    echo '</div>';
?>

.

The Issuse is "echo $tag->name;" returns always the same tag.. can anyone help me to spot the problem / offer a better way
i might have gotten mixed with this script.

Thanks

EDIT 1 - RESPONSE TO: @tollmanz

when i *"print_r($item);"* inside the foreach i get this
(similer to each post that exist with its own details):

stdClass Object ( 
    [ID] => 875 
    [post_author] => 1 
    [post_date] => 2012-06-25 14:34:53 
    [post_date_gmt] => 2012-06-25 11:34:53 
    [post_content] => Content Content Content
    [post_title] => itle Example
    [post_excerpt] => 
    [post_status] => publish 
    [comment_status] => open 
    [ping_status] => open 
    [post_password] => 
    [post_name] => post-name 
    [menu_order] => 0 
    [post_type] => blogs 
    [post_mime_type] => 
    [comment_count] => 0 
    [filter] => raw 
) 

.

Also... When i "echo $item->ID;" i get the correct post id.
.
BUt when i try to *"print_r($posttags);"*
after this line: *"$posttags = get_the_tags($item->ID);"*
.
i get nothing... any ideas why?

share|improve this question
add comment

1 Answer

When you do the following in your code $posttags = get_the_tags($item->term_id);, $item is referring to a post object, not a term object. Therefore, term_id is an invalid property. This should be throwing a PHP notice.

While not certain, I think what you are intending to do is:

$posttags = get_the_tags($item->ID);

since get_the_tags takes a post ID, not a term ID.

share|improve this answer
    
hey @tollmanz - thanks for stoping by ;) - i edited and added some information to my answer after trying to relate to the ID of the post. –  Sagive SEO Jun 26 '12 at 12:35
add comment

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.