marya
marya

Reputation: 167

Excluding specific multiple tags in the tag list in WordPress

I want to exclude 2 tags from the tag list in the following script:

$tags = get_tags();
$html = '<ul>';
foreach ( $tags as $tag ) {
if($tag->slug != "test1"){
$tag_link = get_tag_link( $tag->term_id );
$html .= "<li><a href='{$tag_link}' class='{$tag->slug}'>";
$html .= "{$tag->name}</a></li>";
}}
$html .= '</ul>';
echo $html;

The script works correctly excluding test1 tag. How do I edit the code in order to also exclude another tag named test2?

Upvotes: 0

Views: 955

Answers (1)

Noman
Noman

Reputation: 4116

As per DOCS:

'exclude' Default is an empty string. A comma- or space-delimited string of term ids to exclude from the return array. If 'include' is non-empty, 'exclude' is ignored.

You need to change 1,2 with tag ids of test1 & test2.

$args = array('exclude' => '1,2' );
$tags = get_tags($args);
// .... Rest of your code goes here

Don't forget to remove if check if($tag->slug != "test1"){ as it would be useless with exclude in $args :)

Upvotes: 3

Related Questions