YogeshChauhan.com
WordPress: How to print ACF array field values?
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>';
}


dreamhost

Leave a Reply

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 How to set opacity or transparency using CSS? #3 Pagination in CSS with multiple examples #4 How to make HTML form interactive and using CSS? #5 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #6 How to uninstall Cocoapods from the Mac OS?

Recently Posted

Mar 3 How to embed YouTube or other video links in WordPress? Mar 3 How to change the Login Logo in WordPress? Mar 3 substring() Method in JavaScript Mar 3 Window setInterval() Method in JavaScript Mar 2 How to zoom an element on hover using CSS? Mar 2 the box-sizing property in CSS

You might also like these

Clearwater Seafoods – B2C in ChinaMiscImplicit and Explicit Joins in Oracle SQLSQL/MySQLHow to get ACF values from custom post type?WordPressWhy it’s not a good idea to create Number objects in JavaScript?JavaScriptPostgreSQL BETWEENPostgresHow to add Read More Read Less Button using JavaScript?JavaScriptThe Sort and Compare Functions in JavaScriptJavaScriptWhat is the correct way to enqueue multiple CSS files in WordPress?WordPressUnderstanding the confusing and handy “This” keyword in JavaScriptJavaScriptthe box-sizing property in CSSCSSHow to embed YouTube or other video links in WordPress?WordPressWhat’s a Log File and What are Log File Monitors?Misc