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 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to uninstall Cocoapods from the Mac OS?

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #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
You might also like these
The basics of CSS Box modelCSSHow to render lists inside a component in React?ReactHow to change your WordPress database prefix?WordPressUse eq() method in jQueryjQueryWHERE Clause in PostgresPostgresUPDATE and DELETE Statements in PostgresPostgresClasses in JavaScript: The BasicsJavaScriptHow to convert an HTML radio buttons into a toggle switch using CSS?CSSFor In Loop in Swift for BeginnersSwiftWhat are Identifiers in JavaScript?JavaScriptModules and its Core features in JavaScriptJavaScriptWhat are partials in SCSS (Sass)?SCSS