exbir text according to the output of the variable field

Asked

Viewed 55 times

2

I’m creating a post type post with Advanced Custom Fields. I would like the text to be displayed on a certain line "Secretariat" when the field the_field('contratante') was in use... when the_field('setor02') the word would not be shown.

<?php
while (have_posts()) : the_post(); 
    echo '<h4 class="titulos-widget-internos">'; echo 'Dados do Contrato de Número '; the_title(); echo '</h4>';
    echo '<ul>';
    echo '<li>Origem: <strong>'; the_field('origem'); echo '</strong></li>';
    echo '<li>Contratante: <strong> Secretaria de '; the_field('contratante'); echo '</strong></li>';
    echo '<li>Contratada(o): <strong>'; the_field('contratadao'); echo '</strong></li>';
    echo '<li>Valor: <strong> R$ '; the_field('valor'); echo '</strong></li>';
    echo '<li>Início da vigência: <strong>'; the_field('inicio_da_vigencia'); echo '</strong></li>';
    echo '<li>Fim da vigência: <strong>'; the_field('fim_da_vigencia'); echo '</strong></li>';
    echo '</ul>';
    echo '<p class="objeto">'; echo 'Objeto: '; the_field('objeto'); echo'</p>';
    echo '</div>';
    echo '<a class="botao-padrao" href="'; the_field('contrato_original');  echo '"'; 
    echo 'target="_blank" role="button">Baixar arquivo</a>'; 
    //mh_after_post_content();
    //comments_template();
endwhile; ?> 
  • White, you want the text "Contractor: Secretariat of:..." to disappear when the_field('setor02') has some value other than nothing and that it appears if it exists and if the_field('setor02') does not exist, is that it? or you want to add a new line only with the word secretariat if the conditions I said are met?

2 answers

-1

I haven’t worked with WP and its plugins for a long time. But using logic in your case, I would use a if to check if the field exists, then update the value of the the_field adding the word you want. Searching the plugin site, I saw that there is a function called update_field to update the value. Then it would look like this:

if (the_field('contratante')) {

    update_field('contratante', "Secretaria de " . the_field('contratante'));
}

Then the the_field('contratante') will display the value with the word before.

Edit: the if above would enter just below the loop while.

-1

Look at that, you could make a structure if...

I don’t know if that’s the case!

<?php 
   
if( get_field( 'setor02' ) ) {
 echo "";
} else {
 echo '<li>Contratante: <strong> Secretaria de '; the_field('contratante'); echo '</strong></li>';
}

?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.