WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] PHP: Exclude Tag (9 posts)

  1. Ricardo
    Member
    Posted 1 year ago #

    I am using the following code to generate a list of most used tags:

    [moderator remark: the code below is partially broken; don't use for copy/paste]

    <div id="tab3" class="tab_content">
    					<p class='tag_cloud'>
    					<?php
    					$tags = get_tags(array('orderby' => 'count', 'order' => 'DESC', 'number' => '28'));
    					foreach ((array) $tags as $tag) {
    					?>
    					<?php echo '<a>term_id) . '" rel="tag">' . $tag->name . '</a>';	?>
    					<?php } ?>
                                             </p>
    				</div>

    I want to exclude 1 tag, but I have no idea to do that (I tried using information from the internet but with no luck). Can someone please help me out?

    I use the code here: http://fastforwardandrewind.com

  2. Tara
    Member
    Posted 1 year ago #

    try adding this to the second line of your snippet:
    'exclude' => 'tag1,

    of course change the tag1 with your actual tag name.

  3. alchymyth
    Forum Moderator
    Posted 1 year ago #

    you will need to use the tag ID:

    http://codex.wordpress.org/Function_Reference/get_tags

    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.

  4. Ricardo
    Member
    Posted 1 year ago #

    I am still not getting this to work (I must be doing something wrong).

    I would like to exclude the tag called 'Featured'. So the code should be:

    'exclude' => 'Featured',

    Right?

    Where should I put it? (I have tried multiple combinations, but couldn't get it to work)

    <div id="tab3" class="tab_content">
    					<p class='tag_cloud'>
    					<?php
    					$tags = get_tags(array('orderby' => 'count', 'order' => 'DESC', 'number' => '28'));
    					foreach ((array) $tags as $tag) {
    					?>
    					<?php echo '<a href="' . get_tag_link ($tag->term_id) . '" rel="tag">' . $tag->name . '</a>';	?>
    					<?php } ?>
    					</p>
    				</div>

    Thanks in advance!

  5. alchymyth
    Forum Moderator
    Posted 1 year ago #

    have you read my reply with the link to the corresponding Codex chapter?

  6. Ricardo
    Member
    Posted 1 year ago #

    Yes, but I don't really understand it. Unfortunately there isn't an example on the page where a tag is excluded.

  7. Tara
    Member
    Posted 1 year ago #

    have tried adding 'exclude' => 'tag1' as I recommended in my post?

  8. Mark / t31os
    Moderator
    Posted 1 year ago #

    As Alchymyth pointed out, the exclude parameter expects the term ID, not the slug or name.

    Find out the ID of the term(tag) you want to exclude and reference that in the exclude, eg.

    $args = array(
    	'orderby' => 'count',
    	'order' => 'DESC',
    	'number' => '28',
    	'exclude' => '1' // <-- update 1 to reflect the actual ID of the tag to exclude
    );
    $tags = get_tags( $args );
  9. Ricardo
    Member
    Posted 1 year ago #

    I got it working! Thank you all! :-)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags