the_field – ACF not working in ‘while’ loop


This Content is from Stack Overflow. Question asked by Yaroslav

Main string of code (that doesn’t work):
<span class="price-in-kune"><?php the_field('tariff_price_kn') ?> kn</span>


 $args = array(
  'post_type' => 'tariffs',
  'posts_per_page' => 3,
  'type_of_site' => 'landing_page_type',


 $webTariffs = new WP_Query($args);

 while ($webTariffs->have_posts()) {

  <div class="pricing-item">
    <div class="pricing-item-header">

      <h3><?php the_title() ?></h3>
      <span class="price-in-kune"><?php the_field('tariff_price_kn') ?> kn</span>

<?php } ?>

enter image description here

The ways i tried to solve this problem:

  1. put insted of the_field('tariff_price_kn')echo('hi') – the code worked
  2. add $post_id -> the_field('tariff_price_kn', $post_id)
  3. $currencyKune = get_field('tariff_price_kn'); And then echo $currencyKune

P.S 3) i don’t know exactly where should i put $currencyKune = get_field('tariff_price_kn'), so i put it before while at first time – doesn’t work and at the second time i put it after $webTariffs->the_post();


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?