admin管理员组文章数量:1134567
I'm trying to print some content in all the posts under a certain author only if a specific tag (default wp taxonomy) is set
the tag is "animali permessi" here is the code
$posttags = 'animali permessi';
if (isset($posttags)) {
$supplemento_animali = '<div class="suppl_animali">'. get_the_author_meta( 'supplemento_animali', $post->post_author ) .'</div>';
}
$content = $content . $titolo_prezzo_include . $locazione . $commissione . $consumi . $pulizia_inc . $biancheria_inc . $ac_inc . $titolo_prezzo_non_include . $pulizia_esc . $tassa_soggiorno . $supplemento_animali . $supplemento_culla . $importo_cauzione . $servizio_spiaggia . $suppl_soggiorni_brevi . $biancheria_esc . $asciugamani_esc . $wi_fi_esc . $ac_esc . $saldo . '<footer class="author_bio_section" >'. $author_details . $titolo_affitti . $periodo_affitti . $titolo_orari . $orari .'</footer>';
}
return $content;
}
The code is fine except for the condition The purpose is printing the "extra charge for pets" only if in each post is set the tag "animali permessi" (pets allowed)
I'm trying to print some content in all the posts under a certain author only if a specific tag (default wp taxonomy) is set
the tag is "animali permessi" here is the code
$posttags = 'animali permessi';
if (isset($posttags)) {
$supplemento_animali = '<div class="suppl_animali">'. get_the_author_meta( 'supplemento_animali', $post->post_author ) .'</div>';
}
$content = $content . $titolo_prezzo_include . $locazione . $commissione . $consumi . $pulizia_inc . $biancheria_inc . $ac_inc . $titolo_prezzo_non_include . $pulizia_esc . $tassa_soggiorno . $supplemento_animali . $supplemento_culla . $importo_cauzione . $servizio_spiaggia . $suppl_soggiorni_brevi . $biancheria_esc . $asciugamani_esc . $wi_fi_esc . $ac_esc . $saldo . '<footer class="author_bio_section" >'. $author_details . $titolo_affitti . $periodo_affitti . $titolo_orari . $orari .'</footer>';
}
return $content;
}
The code is fine except for the condition The purpose is printing the "extra charge for pets" only if in each post is set the tag "animali permessi" (pets allowed)
Share Improve this question edited Sep 5, 2023 at 15:16 Andrea Sacconi asked Sep 5, 2023 at 15:11 Andrea SacconiAndrea Sacconi 797 bronze badges 1 |1 Answer
Reset to default 3isset()
checks to see if a variable is set, ie, has a value other than null
. The way you're using it will always return true
because you've set $posttags
to 'animali permessi'
, which is not null
.
I think you're looking for the WordPress function has_tag()
instead.
if (has_tag( 'animali permessi', $post ) ) {
$supplemento_animali = '<div class="suppl_animali">'. get_the_author_meta( 'supplemento_animali', $post->post_author ) .'</div>';
}
本文标签: phpConditional concerning a selected tag not working
版权声明:本文标题:php - Conditional concerning a selected tag not working 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736815647a1954077.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
isset
isn't a WordPress function, it has nothing to do with post tags, it's a PHP function to see if a variable exists/is set – Tom J Nowell ♦ Commented Sep 5, 2023 at 16:37