0

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!

1 Answer 1

0

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);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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