WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking to see if it's possible to find and remove duplicates from the arrays generated below. I've tried array_unique array_merge and they haven't worked.

$category = get_the_category();
$tags = wp_get_post_tags($post->ID);

As an example, there is a potential that the word "Apparel" may appear in both Category and Tag for the post. With the "raw" method above, Apparel would appear twice in my output. I'm only looking to include it once. At this point in time, I believe it is ok if both lists are merged and all words are part of 1 output.

Example: %23Apparel %23Auto %23Mens

Then, once the output is generated, I need to add HTML URLEncode %23 to the beginning of each word.

Would appreciate your input.

share|improve this question
up vote 1 down vote accepted

If you only want to collect the category+tag names into the output, you can try this

global $post;

$tags = wp_get_post_tags($post->ID);
foreach($tags as $tag){

$cats = get_the_category($post->ID);
foreach($cats as $cat){

echo implode(" ",$words);
share|improve this answer
Worked great except for one thing. The implode ignores the first word in the string. Is there a way to have the %23 apply to all? – Pat Mar 12 '13 at 12:22
yes sure, you can do this echo "%23".implode(" %23",$words); in the previous revision of the answer or use the updated answer. – birgire Mar 12 '13 at 12:31
The revised answer works great. I was trying to take your original code and add a foreach onto the $words array and was failing. Thank you! – Pat Mar 12 '13 at 12:40

Your Answer


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.