Olá, já tenho uma relação em uma categoria… Mas, gostaria de adicionar outra relação porém dentro o repetidor dentro dela.
Meu código atual consiste em verificar se existe um subtopico e se não tiver ele irá exibir os posts que foram atrelados na relação.
Desejo continuar com essa regra e adicionar um regra que eu também possa adicionar uma nova relação porém que contenha repetição.
Por favor olhem meu código. Como eu insiro um novo campo de repetidor e dentro dele ter uma relação e depois exibir no front end?
<?php
$ts = get_terms( array(
‘taxonomy’ => ‘destinos’,
‘child_of’ => $term->term_id,
‘parent’ => $term->term_id,
‘meta_key’ => ‘peso_destinos’,
‘orderby’ => ‘meta_value’,
‘order’ => ‘DESC’
) );
if ( count($ts) > 0 ) {
foreach ( $ts as $t ) :
?>
<li class=”category-item col link-seo”>
<div class=”col category-image”>
” alt=”viagem-para-paris-destaque”>
</div>
<div class=”col”>
slug ?>” title=”<?= $t->name ?>”>
<h2 class=”sub-title upper-all text-bold”><?= $t->name ?></h2>
<?php if ( get_field(‘preco_destinos’, $t) ) : ?>
<div class=”price-pac”>
<span class=”price-start”>A partir de:</span>
<span class=”price-value”><span class=”text-bold open-font”><?= get_field(‘preco_destinos’, $t) ?></span><?php endif; ?>
<span class=”price-start”><?= get_field(‘selecao_por_tipo’, $t) ?>
</span>
</div>
</div>
<?php endforeach; } else { ?>
<?php
// WP_Query arguments
$args = array(
‘post_type’ => array( ‘pacotes’ ),
‘post_per_page’ => -1,
‘term’ => $term->slug,
‘taxonomy’ => ‘destinos’,
‘meta_key’ => ‘peso_pacotes’,
‘orderby’ => ‘meta_value’,
‘order’ => ‘DESC’
);
// The Query
$query = new WP_Query( $args );
// The Loop
if ( $query->have_posts() and !get_field(‘ordem_pacote’, $term) ) {
while ( $query->have_posts() ) {
$query->the_post();
?>
<li class=”category-item col link-seo”>
<div class=”col category-image”>
<?php $imagem = get_field(‘imagem_destaque_pacotes’); ?>
<?php $imagem_other = get_field(‘imagem’); ?>
<?php $cat_img = catch_that_image(); ?>
<?php if ( $imagem ) : ?>
” alt=”<?= $imagem[‘title’] ?>”>
<?php elseif ( !empty($cat_img) ) : ?>
” alt=”<?= the_title() ?>”>
<?php elseif ( $imagem_other ) : ?>
” alt=”<?= $imagem_other[‘title’] ?>”>
<?php else: ?>
“>
<?php endif; ?>
</div>
<div class=”col”>
” title=”<?php the_title(); ?>”>
<h2 class=”sub-title text-bold”><?= the_title(); ?>
</h2> <p class=”sub-title text-bold”> <?= get_field (‘subtitulo’) ?></p>
<div class=”roteiro-pac”>
<span><?= get_field(‘roteiro_texto_pacotes’) ?></span>
</div>
<div class=”durac-pac”>
<span><?= get_field(‘duracao_pacotes’) ?></span>
</div>
<div class=”price-pac”>
<span class=”price-start”><?php the_field(‘selecao_de_parcelamento’); ?></span>
<?php
$valor = get_field(‘a_partir_de_pacotes’);
$local = get_the_terms( get_the_ID(), ‘localizacao’ );
if ( $local[0]->name == ‘Internacional’ ) {
$moeda = “US$”;
$valor_final = moeda(‘dolar’, $valor);
} else {
$moeda = “R$”;
$valor_final = moeda(‘real’, $valor);
}
?>
<span class=”price-value”><span class=”text-bold open-font”><?= $moeda ?> <?= $valor_final ?></span></span>
<span class=”price-start”><?php the_field(‘valor_referente’); ?></span>
</div>
</div>
<?php
}
} else {
?>
<?php
//AYRES
$posts = get_field(‘ordem_pacote’, $term);
?>
<ul class=”category-items-list flex-start flex-wrap”>
<?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>
<li class=”category-item col link-seo”>
<div class=”col category-image”>
<?php $imagem = get_field(‘imagem_destaque_pacotes’); ?>
<?php $imagem_other = get_field(‘imagem’); ?>
<?php $cat_img = catch_that_image(); ?>
<?php if ( $imagem ) : ?>
” alt=”<?= $imagem[‘title’] ?>”>
<?php elseif ( !empty($cat_img) ) : ?>
” alt=”<?= the_title() ?>”>
<?php elseif ( $imagem_other ) : ?>
” alt=”<?= $imagem_other[‘title’] ?>”>
<?php else: ?>
“>
<?php endif; ?>
</div>
<div class=”col”>
” title=”<?= the_title(); ?>”>
<h2 class=”sub-title text-bold”><?= the_title(); ?>
</h2>
<p class=”sub-title text-bold”><?= get_field (‘subtitulo’) ?></p>
<div class=”roteiro-pac”>
<span><?= get_field(‘roteiro_texto_pacotes’) ?></span>
</div>
<div class=”durac-pac”>
<span><?= get_field(‘duracao_pacotes’) ?></span>
</div>
<div class=”price-pac”>
<?php
$valor = get_field(‘a_partir_de_pacotes’);
$local = get_the_terms(get_the_ID() , ‘localizacao’);
if ($local[0]->name == ‘Internacional’)
{
$moeda = “US$”;
$valor_final = moeda(‘dolar’, $valor);
}
else
{
$moeda = “R$”;
$valor_final = moeda(‘real’, $valor);
}
?>
<span class=”price-start”><?php the_field(‘selecao_de_parcelamento’); ?></span>
<span class=”price-value”><span class=”text-bold open-font”><?=$moeda ?> <?=$valor_final ?></span></span>
<span class=”price-start”><?php the_field(‘valor_referente’); ?></span>
</div>
</div>
<?php endforeach; ?>
<?php wp_reset_postdata(); // IMPORTANT – reset the $post object so the rest of the page works correctly ?>
<?php
}
// Restore original Post Data
wp_reset_postdata();
?>
<?php } ?>
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
CPT registration is coming to ACF! We demoed the new feature during the most recent session of ACF Chat Fridays. Check out the summary for the details. https://t.co/k2KQ3WWBAz
— Advanced Custom Fields (@wp_acf) March 7, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.