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

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
WordPress: How to display slider repeater fields in ACF?WordPressHow to Commit and Rollback Changes in SQL?SQL/MySQLSteps to Secure a VPNMiscellaneousHow to uninstall Cocoapods from the Mac OS?MiscellaneousCheck If a String Contains a Specific Word in PHPPHPContainers 101: What are containers?MiscellaneousShould we ever delete data from a database?MiscellaneousHow to change the Login Logo in WordPress?WordPressColleague UI Basics: Accessing the user interfaceColleagueIs monitoring an employee’s work on a computer a desirable or undesirable activity?MiscellaneousIf statement shorthand examples in JavaScriptJavaScriptThe Difference Between isNaN() Method And isNaN() Function In JavaScriptJavaScript