Yogesh Chauhan's Blog

WordPress: How to print ACF array field values?

in WordPress on February 22, 2021

Advanced Custom Fields has tons of exciting and amazing options to make your website feature rich. Many of those fields can return values in arrays. here are the examples to print the array values.

Using forEach loop



$values = get_field('field_name');
if($values)
{
  echo '<ul>';
  foreach($values as $value)
  {
    echo '<li>' . $value . '</li>';
  }
  echo '</ul>';
}


Using for loop



$values = get_field('field_name');
if($values)
{
  echo '<ul>';
  for($i = 0; $i++; $i <= count($values))
  {
    echo '<li>' . $value[$i] . '</li>';
  }
  echo '</ul>';
}


Using while loop



$values = get_field('field_name');
if($values)
{
  echo '<ul>';
  $i = 0;
  while($i <= count($values)) {
    echo '<li>' . $value[$i] . '</li>';
    $i++;
  } 
  echo '</ul>';
}



Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 How to add Read More Read Less Button using JavaScript? #3 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface #Jan 14 How to display a student’s individual transcript in Colleague? #Jan 11 How to install PuTTY on a MacOS?
You might also like these
WordPress Plugin: Things to knowWordPressHow to get category name using post id in WordPress?WordPressHow to use $IF operator in Envision Basic?Envision BasicHow to create HTML elements with ID and class using JavaScript?HTMLHAVING Clause in Postgres with Examples in All Aggregate FunctionsPostgresWhy do we need HAVING Clause in SQL?SQL/MySQLWhat is React? Learn the basicsReactWhat are Class Constants in PHP?PHPRIGHT JOIN in PostgresPostgresSorting Object Arrays in JavaScriptJavaScriptWordPress get_posts ExamplesWordPressHow to disable scrolling on html body on menu click using JavaScript?JavaScript