get_fields

The advanced-custom-fields get fields function.

Published Date - March 18, 2020

Description

get_fields( $post_id, $format_value );

Parameters

  1. $post_id

  2. $format_value


Usage

The following example is for adding a hook callback.

if ( !function_exists( 'get_fields' ) ) {
    require_once ABSPATH . PLUGINDIR . 'advanced-custom-fieldsadvanced-custom-fields/includes/api/api-template.php';
}

// The input(s). 
$post_id = false;
$format_value = true;

// NOTICE! Understand what this does before running.
$result = get_fields( $post_id, $format_value );
            

Defined

The function is defined in the following location(s).

advanced-custom-fields/includes/api/api-template.php

function get_fields( $post_id = false, $format_value = true ) {
	
	// vars
	$fields = get_field_objects( $post_id, $format_value );
	$meta = array();
	
	
	// bail early
	if( !$fields ) return false;
	
	
	// populate
	foreach( $fields as $k => $field ) {
		
		$meta[ $k ] = $field['value'];
		
	}
	
	
	// return
	return $meta;	
	
}