Skip to content

Instantly share code, notes, and snippets.

@alwayscoding
Created March 11, 2013 15:38
Show Gist options
  • Save alwayscoding/5135112 to your computer and use it in GitHub Desktop.
Save alwayscoding/5135112 to your computer and use it in GitHub Desktop.
WORDPRESS: TAGS IN A CATEGORY
query_posts('category_name=category-slug');
if (have_posts()) :
while (have_posts()) : the_post();
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
$all_tags_arr[] = $tag->name; //USING JUST $tag MAKING $all_tags_arr A MULTI-DIMENSIONAL ARRAY, WHICH DOES WORK WITH array_unique
}
}
endwhile;
endif;
$tags_arr = array_unique($all_tags_arr); //REMOVES DUPLICATES
foreach ($tags_arr as $tag) {
# code...
echo $tag;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment