Is there a way to work with a specific the_field from an already queried post?

I’m relatively new to working with wordpress and php in general, so I’d like to know if someone can help me with this.

I have a custom query that looks like this

<?php
$args = array( //argumentos
‘numberposts’ => -1,
‘post_type’ => ‘cdts’,
‘meta_key’ => ‘cargo’,
‘meta_value’ => ‘p’
);

$the_query = new WP_Query( $args ); //custom query
?>

<?php if( $the_query->have_posts()): //loop do wordpress ?>
<ul class=”lista_candidatos”>
<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li>
<a href=”<?php the_field(‘link’); ?>”>
<?php the_field(‘nome’); ?> <?php the_field(‘numero_partido’); ?> (<?php the_field(‘sigla_partido’); ?>)
</a>
<p class=”ano_cand”><?php the_field(‘ano_candidatura’); ?></p>
</li>
<?php endwhile; ?>
</ul>
<?php else : ?>
<p class=”err_no_candidato”>Sem candidatos cadastrados.</p>
<?php endif; ?>

<?php wp_reset_query(); //restaura os queries do wp ?>

And I have an ACF field that’s called “ano_candidatura”. I’d like to know if there is a way to make different things with different “ano_candidatura”, like creating different tabs for each value.

Maybe I’m doing something wrong I try to do, for example,

<?php if( the_field(‘ano_candidatura’) == ‘2018’): ?>

because when I do this, it just prints ‘2018’ to the page.

So, is there a way I can create different html for different the_field values and equal html to equivalent values?

Read more here:: Is there a way to work with a specific the_field from an already queried post?

Leave a Reply

Your email address will not be published. Required fields are marked *