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 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #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

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
How to Secure Web or Mobile Browsers?MiscellaneousHow to add Local State to a Class in React?ReactThe Differences Between HAVING Clause and WHERE Clause in SQLSQL/MySQLHow to create an empty array in Swift?SwiftHow does Binding work in JavaScript?JavaScriptSQL ALL OperatorSQL/MySQL@use rule in SCSS (Sass)SCSSHow to modify the latest post array using get_posts() in WordPress?WordPressHow to show and hide an element on click in React?ReactHow to disable scrolling on html body on menu click using JavaScript?JavaScriptList of social media icon logo color codes in HEXMiscellaneousClearwater Seafoods – B2C in ChinaMiscellaneous