We need to post object for each type differently in Advanced Custom Field ACF. Here we will see how to Get a value from different field objects ACF.

The Default Parameter is :

get_field($selector, [$post_id], [$format_value]);

$selector (string) (Required) The field name or field key
$post_id (mixed) (Optional) The post ID where the value is saved. Defaults to the current post
$format_value (bool) (Optional) Whether to apply formatting logic. Defaults to true

Get a value from the current post

$value = get_field( "my_field" );

Get a value from a specific post

$value = get_field( "my_field", 123 );

Get a value For Category

$post_id = "category_4"; // category term ID = 4
$value = get_field( 'my_field', $post_id );

Get a value For User

$user_id = "user_2"; // user ID = 2
$value = get_field( 'my_field', $user_id );

Get a value For Custom Taxonomy

$post_id = "program_5"; // program (custom taxonomy) term ID = 5
$value = get_field( 'my_field', $post_id );

Get a value For options Page

$post_id = "option"; // options page
$value = get_field( 'my_field', $post_id );
There are currently no comments.