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'm encountering an issue when I want to display some articles based on a "composed" tag like "amnesty-international". The query doesn't return any results. The fact is I have two article tagged with this slug. This is the code I use in the template archive.php:

$current_tag =  single_term_title("", false);
$args= array(
    'post_type' => 'adverts',
    'tag' => $current_tag
);

$adsQuery = new WP_Query($args);

So this url doesnt return anything : http://www.mydomain.net/tag/amnesty-international/

Should I use another function ?

share|improve this question
    
single_term_title doesn't return slugs. It returns titles. It will return "Howdy Ho" instead of "howdy-ho'. See: wordpress.stackexchange.com/questions/54544/… –  s_ha_dum Jan 24 '13 at 15:34
    
possible duplicate of Exclude Specific Term from Search –  kaiser Jan 24 '13 at 16:24
    
@s_ha_dum Thx for your explanation, the topic did the trick. –  aguidis Jan 24 '13 at 21:38

1 Answer 1

Thanks to a similar topic I can do it with :

$tag       = get_queried_object();
$tag_slug  = $tag->slug;

Or with this snippet :

$current_tag =  single_term_title("", false);
tag_slug = str_replace(' ', '-', $current_tag);
share|improve this answer

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.