YogeshChauhan . com

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>';
}


amazon

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 How to Use SQL MAX() Function with Dates? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

Jun 16 What are Stored Procedures for SQL Server? Jun 16 What are Class Constants in PHP? Jun 15 A short basic guide on states in React Jun 15 How to define constants in PHP? Jun 15 How to define visibility for a property in PHP? Jun 15 How to use @if and @else in SCSS?

You might also like these

How to define visibility for a property in PHP?PHPCan We Use For Loop to Loop Through Associative Arrays in PHP?PHPEverything you need to know about ANY, SOME and ALL Operators in PostgresPostgresList of all Pseudo Elements in CSSCSSHow to refresh a page using PHP at regularly occurring intervals?PHP@forward modules with a prefix in SCSS (Sass)SCSSTackle Accessibility in React with JSXReactThe difference between Class declarations and Class expressions in JavaScriptJavaScriptWhat are “holes” in a React component?ReactHow to get current timestamp in Swift 4 and 5?SwiftHow to import MySQL small sample database into phpMySQL?SQL/MySQLHow to use PHPMailer to send an Email via Gmail SMTP Server?PHP