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 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
Add a comment  | 

1 Answer 1

Reset to default 3

isset() 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