- get_field_object()
- Parameters
- Return
- Examples
- Display a field’s label and value
- Display a field’s label and value from a specific post
- Retrieve a field using its key
- Display field type specific data
- Related
- On this page
- In this category
- Fetch label and value from form in php
- Recommended Answers Collapse Answers
- WPAcademic / get-acf-label-from-name.php
- PHP get_label_name Examples
- Получить значение label через input
get_field_object()
Each field contains many settings such as a label, name and type. This function can be used to load these settings as an array along with the field’s value.
Parameters
get_field_object($selector, [$post_id = false], [$format_value = true], [$load_value = true]);
- $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.
- $load_value (bool)(Optional) Whether to load the field’s value. Defaults to true.
Return
(array) This function will return an array looking something like the following. Please note that each field contains unique settings.
array( 'ID' => 0, 'key' => '', 'label' => '', 'name' => '', 'prefix' => '', 'type' => 'text', 'value' => null, 'menu_order' => 0, 'instructions' => '', 'required' => 0, 'id' => '', 'class' => '', 'conditional_logic' => 0, 'parent' => 0, 'wrapper' => array( 'width' => '', 'class' => '', 'id' => '' ) );
Examples
Display a field’s label and value
This example shows how to load a field and display its label and value.
Display a field’s label and value from a specific post
This example shows how to load a field and display its label and value from the post with >
Retrieve a field using its key
In some circumstances it may be necessary to load a field by its key, such as when a value has not yet been saved. This example shows how to load a field using its key.
Display field type specific data
Some field types store extra data such as the Select field. This example shows how to loop over a Select field’s choices and display them in a list.
Related
On this page
In this category
- acf_add_options_page()
- acf_add_options_sub_page()
- acf_form_head()
- acf_form()
- acf_register_block_type()
- acf_register_form()
- acf_set_options_page_capability()
- acf_set_options_page_menu()
- acf_set_options_page_title()
- add_row()
- add_sub_row()
- delete_field()
- delete_row()
- delete_sub_field()
- delete_sub_row()
- get_field_object()
- get_field_objects()
- get_field()
- get_fields()
- get_row_index()
- get_row_layout()
- get_row()
- get_sub_field_object()
- get_sub_field()
- has_sub_field()
- have_rows()
- Shortcode
- the_field()
- the_flexible_field()
- the_repeater_field()
- the_sub_field()
- update_field()
- update_row()
- update_sub_field()
- update_sub_row()
Fetch label and value from form in php
What I now want to do in the php document is to fetch the value and the label and print it in the php document. I can get the value but dont know how to get the lable. Any help would be nice.
- 3 Contributors
- 5 Replies
- 9K Views
- 6 Years Discussion Span
- Latest Post 5 Years Ago Latest Post by Rashid_4
Recommended Answers Collapse Answers
You can not get labels after form submission.
You can create hidden type field and value can be same as label, then when form submitted you can get hidden field value for labeling.
Try this code, you will understand how to use hidden field.
'; echo '
Name Label: '.$_POST['name_label']; echo '
Name Value: '.$_POST['name']; echo '
Email Label: '.$_POST['email_label']; echo '
Email Value: '.$_POST['email']; exit; > ?>
All 5 Replies
You can not get labels after form submission.
You can create hidden type field and value can be same as label, then when form submitted you can get hidden field value for labeling.
Does the hidden types need a unique name? Cause I have tried something similar with the the name and value where I give the same name as label but this does not work since "name" needs to have unique names and i have some repeating label namnes. And how would I get these hidden types in my php? I am kind of newbish. Atm I do
foreach($_GET as $name => $value) < echo $name . ': ' . $value.""; >
'; echo '
Name Label: '.$_POST['name_label']; echo '
Name Value: '.$_POST['name']; echo '
Email Label: '.$_POST['email_label']; echo '
Email Value: '.$_POST['email']; exit; > ?>
"; foreach($_POST as $name => $value) < if($counter == 0) < echo $value.': '; $counter = 1; >else < echo $value.""; $counter = 0; > $counter2 = $counter2 + 1; if($counter2 == 18) < echo " if($counter2 == 44) < echo "
"; > if($counter2 == 60) < echo "
"; > if($counter2 == 76) < echo "
"; > if($counter2 == 92) < echo "
"; > if($counter2 == 104) < echo "
"; > if($counter2 == 116) < echo "