1

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?

closed as off-topic by Milo, fuxia Sep 14 '18 at 8:04

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    use get_field instead of the_field – Milo Sep 14 '18 at 5:30
  • thanks!!! didn't knew there was a difference between get_field and the_field – lordkleiton Sep 14 '18 at 17:30
0

Try the below code

$ano_candidatura_value = get_field( 'ano_candidatura', $post->ID );

if($ano_candidatura_value == '2018') : 

  // The html code you want to implement

endif;

Hope this helps.

0

You can use like this

if( get_field('ano_candidatura',get_the_ID()) == '2018'):

Not the answer you're looking for? Browse other questions tagged or ask your own question.