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.

My scenario: I have a part of a site which retrieves all post_tags terms for a specific category

the code:

                query_posts('category_name='. $category[0]->cat_name);
                if (have_posts()) : while (have_posts()) : the_post();
                    $posttags = get_the_tags();
                    if ($posttags) {
                        foreach($posttags as $tag) {
                            $all_tags_arr[] = $tag -> name; 
                        }
                    }
                endwhile; endif; 


                $tags_arr = array_unique($all_tags_arr); 

                foreach ($tags_arr as $cat_by_tag) {
                    $output_promotion .= '<li><a href="' . get_bloginfo('url'). '/' . $category[0]->cat_name . '/' . ????? . '/">'. $cat_by_tag .'</a></li>';
                }

                echo $output_promotion;

This all works fine, the code retrieves all post_tags and removes duplicates. I'm stuck now with the post slug. What I want is: retrieve post slug by post_tag term.

Example:

Post title: ABC Post

post slug: abc-post

Tag in that post: ABC Tag

I need something like this:

<a href="http://site/abc-post">ABC Tag</a>

Anyone can help?

Thanks in advance!

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

i am not sure but try this:

query_posts('category_name='. $category[0]->cat_name);
                if (have_posts()) : while (have_posts()) : the_post();
                    $posttags = get_the_tags();
                    if ($posttags) {
                        foreach($posttags as $tag) {
                            $all_tags_arr[] = array($tag->name,wp_basename(get_permalink())); 
                        }
                    }

                endwhile; endif; 

                foreach ($all_tags_arr as $cat_by_tag) {
                    $output_promotion .= '<li><a href="' . get_bloginfo('url'). '/' . $cat_by_tag[1] . '/">'. $cat_by_tag[0] .'</a></li>';
                }

                print_r($output_promotion);
share|improve this answer
    
Thanks for help Eyal, it worked :) –  joe.moJito May 12 '12 at 14:31
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.