L
L
Lenwoot2016-02-25 15:41:02
Programming
Lenwoot, 2016-02-25 15:41:02

How to disable the display of posts by tag?

Please tell me how to exclude the output of records by tag? I tried several options, in the end it did not work ..

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Kozlov, 2016-02-26
@trampick

Use a function:
after calling
It, it will return an array of objects, something like this:

Array
(
   [0] => stdClass Object
     (
       [term_id] => 4
       [name] => tag2
       [slug] => tag2
       [term_group] => 0
       [term_taxonomy_id] => 4
       [taxonomy] => post_tag
       [description] => 
       [parent] => 0
       [count] => 7
     )

   [1] => stdClass Object
     (
       [term_id] => 7
       [name] => tag5
       [slug] => tag5
       [term_group] => 0
       [term_taxonomy_id] => 7
       [taxonomy] => post_tag
       [description] => 
       [parent] => 0
       [count] => 6
     )

   [2] => stdClass Object
     (
       [term_id] => 16
       [name] => tag6
       [slug] => tag6
       [term_group] => 0
       [term_taxonomy_id] => 16
       [taxonomy] => post_tag
       [description] => 
       [parent] => 0
       [count] => 2<code lang="php">

</code>
     )

)

Next, do something like this:
<?php
$a = true; //Предполагаем что пост это выводим
$t = wp_get_post_tags($post->ID);//получаем все теги для этого поста
foreach($t as $tt) {
//перебираем все теги
if ($tt->name == 'мой тег') {//здесь условие сравнения. В данном случае по имени тега. Можно использовать и другие условия для slug,term_id. Как считаете нужным.
$a =false;
break;
}
}
if ($a == true) {
?>
<div class="post excerpt2">
<?php
}

The second option is to correctly set the arguments in query_posts. Here you need to google examples on the topic wp_query_post

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question