L
L
Lenwoot2015-08-10 14:40:22
PHP
Lenwoot, 2015-08-10 14:40:22

How to disable the display of tags with id 2 and 4?

There is a code that displays the tags as a list. The question is, how to disable the output of tags with id 2 and 4?

<?php
                            $tags        = get_tags( 'orderby=name&order=ASC' );
                            $capital     = '';
                            $i           = 0;
                            $cols_number = 1; 
                            $cut         = ceil( count( $tags ) / $cols_number );
                            $cutter      = $cut;
                            $letter_i    = 0;
                            $output      = '<div class="columnia">';
                            foreach ( $tags as $tag ) {
                                $i ++;
                                $firstletter = mb_substr( $tag->name, 0, 1 );
                                $firstletter = mb_strtoupper($firstletter);
                                if ( $firstletter != $capital ) {
                                    $letter_i ++;
                                    if ( $letter_i != 1 ) {
                                        $output .= '</p>';
                                    }
                                    if ( $i > $cutter ) {
                                        $output .= '</div><div class="columnia">';
                                        $cutter = $cutter + $cut;
                                    }
                                    $capital = $firstletter;
                                }
                                $term = get_term_by( 'id', (int) $tag->term_id, 'post_tag' );
                                $output .= '<p class="p00"><a href="' . get_term_link( (int) $tag->term_id, 'post_tag' ) . '">' . $tag->name . '</a>';
                            }
                            echo $output . '</p></div>';
                            ?>

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Petrochenko, 2015-08-10
@powepmakerru

Approximately the principle is

foreach ( $tags as $tag ) {

if($tag->term_id == 1  || $tag->term_id == 2)
 continue;
//далее ваш код

}

if I understand you correctly)

T
tvolf, 2015-08-10
@tvolf

I don’t know if I understood the essence of the task correctly, but what if at the very beginning of the for loop we write, for example, like this:
===
...
foreach ( $tags as $tag ) {
if (in_array($tag->id, array(2,4)))
...
===
?

M
maximw, 2015-08-10
@maximw

...
foreach ( $tags as $tag ) {
if (in_array($tag->id, array(2,4) )) {
  continue;
}
...

Simple, but crooked.
In general, if such a selection is needed, then it is better to implement it in get_tags()
get_tags( 'where=id not in (2,4)&orderby=name&order=ASC' );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question