Hello. We have a bug when working with Gutenberg sides with ACF fields.
WordPress: 6.5.5
Apache: 2.4.61
PHP: 8.1.29
Advanced Custom Fields PRO: 6.3.9
Gutenberg blocks are registered via block.json and register_block_type. Fields for the block are added via ACF.
The problem:
Sometimes when I add a block in the editor, the data for it does not load.
This is what a block added for the first time should look like:
<!– wp:vp-swan/gallery {“name”:”vp-swan/gallery”,”data”:{“field_66f28000f6c68″:””,”field_66c196c31255b”:”1″,”field_66bcecc968768″:{“row-0”:{“field_66bcecdf68769″:””,”field_66bcecec6876a”:””}}},”mode”:”edit”} /–>
But very often the block is added like this:
<!– wp:vp-swan/gallery {“name”:”vp-swan/gallery”,”data”:{},”mode”:”edit”} /–>
The most interesting thing is that the block in the visual editor looks normal, and I can add data there. But after saving, the data is not saved and is lost.
I also noticed that this happens because when adding a block, there is no request to admin-ajax.php with action:acf/ajax/fetch-block, which is probably why the data is not loaded.
I have an ACF form on the front end that creates an entry for a custom post type. I don’t want to show the post title field for the user to edit, but I want to set it to something like “News Item 123456” when the form is submitted, where 123456 uses time(). Below is my code for showing/submitting the form which does work.
<?php
// Show ACF Form On Front End Via ShortCode
// acf_form_head(); added to header.php
// Function for the shortcode
function bwp_acf_form_function($attr) {
// If ACF isn't running then exit
if (!function_exists('acf_form')) {
return;
}
// Buffer data instead of outputting it
ob_start();
// Unique form ID to avoid conflicts
$form_id = 'bwp-acf-form-' . uniqid();
// Debug: Log form ID and request data
error_log('Rendering ACF Form with ID: ' . $form_id);
error_log('Request data: ' . print_r($_REQUEST, true));
// Display ACF form
acf_form(array(
'id' => $form_id,
'post_id' => 'new_post',
'new_post' => array(
'post_type' => 'daily-message',
'post_status' => 'draft',
),
'field_groups' => array($attr['field_group_id']),
'post_title' => false, // False to auto-populate
'post_content' => false, // False to not use for content
'submit_value' => __("Add CSCC Daily Messenger Info", 'acf'),
'updated_message' => __("Daily Messenger Post Added", 'acf'),
'return' => '', // Redirect URL after saving (empty string means no redirect)
'html_after_fields'=> '<input type="hidden" name="my_form_nonce" value="' . wp_create_nonce('my_form_nonce_action') . '">', // Add nonce for security
));
// Empty the buffer data
return ob_get_clean();
}
// Add the shortcode
add_shortcode('bwp_acf_form', 'bwp_acf_form_function');
?>
I have a fresh WP install and am working with an ACF front end form (I’ve used ACF before but this is my first time using a front end ACF form). Everything is working but it’s posting twice.
I’m adding the code via a custom plugin I created just for this, using a shortcode on the page. Below is the code I am using that posts the entry twice. Any ideas what could be causing this?
<?php
// Show ACF Form On Front End Via ShortCode
// Info from this video: https://www.youtube.com/watch?v=MSIc7rnZ2U0
// Code to show form
add_action('init', 'brandpage_form_head');
function brandpage_form_head() {
acf_form_head();
}
// Function for the shortcode
function bwp_acf_form_function($attr) {
// If ACF isn't running then exit
if (!function_exists('acf_form')) {
return;
}
// Buffer data instead of outputting it
ob_start();
// Unique form ID to avoid conflicts
$form_id = 'bwp-acf-form-' . uniqid();
// Debug: Log form ID and request data
error_log('Rendering ACF Form with ID: ' . $form_id);
error_log('Request data: ' . print_r($_REQUEST, true));
// Display ACF form
acf_form(array(
'id' => $form_id,
'post_id' => 'new_post',
'new_post' => array(
'post_type' => 'daily-message',
'post_status' => 'draft',
),
'field_groups' => array($attr['field_group_id']),
'post_title' => false, // False to auto-populate
'post_content' => false, // False to not use for content
'submit_value' => __("Add CSCC Daily Messenger Info", 'acf'),
'updated_message' => __("Daily Messenger Post Added", 'acf'),
'return' => '', // Redirect URL after saving (empty string means no redirect)
'html_after_fields'=> '<input type="hidden" name="my_form_nonce" value="' . wp_create_nonce('my_form_nonce_action') . '">', // Add nonce for security
));
// Empty the buffer data
return ob_get_clean();
}
// Add the shortcode
add_shortcode('bwp_acf_form', 'bwp_acf_form_function');
?>
acf local field group issue when saving page
Hello everyone !
I’m currently creating a plugin for a client. To create a plugin as isolated as i can, i decided to generate a custom wordpress page, forced in draft and menu_order -999. In this page, i want to generate ACF fields.
To generate the page, i’m doing this :
function GenerateCustomPage(){
global $option_page_title;
if (!get_page_by_path(sanitize_title($option_page_title))) { //If page doesn't exist
$page_args = array(
'post_title' => $page_title,
'post_name' => sanitize_title($option_page_title),
'post_content' => '',
'post_status' => 'draft',
'post_type' => 'page',
'menu_order' => -999,
'post_author' => 1,
);
wp_insert_post($page_args);
} else { //If the page exist, force draft and menu order
$page = get_page_by_path(sanitize_title($option_page_title));
$page->menu_order = -999;
$page->post_status = 'draft';
wp_update_post($page);
}
}
add_action('after_setup_theme', 'GenerateCustomPage');
To generate ACF fields, i’m usint the init hook. Such as :
function GenerateACFOptions() {
global $option_page_title;
if ( ! function_exists( 'acf_add_local_field_group' ) ) {
return;
}
acf_add_local_field_group( array(
'key' => 'group_floating_bar_options',
'title' => 'Floating Bar Options',
'fields' => array(
array(
'key' => 'field_floating_bar_item_1',
'label' => 'Item 1',
'name' => 'item_1',
'aria-label' => '',
'type' => 'group',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'layout' => 'table',
'sub_fields' => array(
array(
'key' => 'field_floating_bar_item_1_display',
'label' => 'Display',
'name' => 'item_display',
'aria-label' => '',
'type' => 'true_false',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'message' => '',
'default_value' => 0,
'ui_on_text' => '',
'ui_off_text' => '',
'ui' => 1,
),
array(
'key' => 'field_floating_bar_item_1_link',
'label' => 'Lien',
'name' => 'item_link',
'aria-label' => '',
'type' => 'link',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'return_format' => 'array',
),
array(
'key' => 'field_floating_bar_item_1_image',
'label' => 'image',
'name' => 'item_image',
'aria-label' => '',
'type' => 'image',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'return_format' => 'array',
'library' => 'all',
'min_width' => '',
'min_height' => '',
'min_size' => '',
'max_width' => '',
'max_height' => '',
'max_size' => '',
'mime_types' => 'png, svg',
'preview_size' => 'medium',
),
),
),array(
'key' => 'field_floating_bar_item_2',
'label' => 'Item 2',
'name' => 'item_2',
'aria-label' => '',
'type' => 'group',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'layout' => 'table',
'sub_fields' => array(
array(
'key' => 'field_floating_bar_item_2_display',
'label' => 'Display',
'name' => 'item_display',
'aria-label' => '',
'type' => 'true_false',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'message' => '',
'default_value' => 0,
'ui_on_text' => '',
'ui_off_text' => '',
'ui' => 1,
),
array(
'key' => 'field_floating_bar_item_2_link',
'label' => 'Lien',
'name' => 'item_link',
'aria-label' => '',
'type' => 'link',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'return_format' => 'array',
),
array(
'key' => 'field_floating_bar_item_2_image',
'label' => 'image',
'name' => 'item_image',
'aria-label' => '',
'type' => 'image',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'return_format' => 'array',
'library' => 'all',
'min_width' => '',
'min_height' => '',
'min_size' => '',
'max_width' => '',
'max_height' => '',
'max_size' => '',
'mime_types' => 'png, svg',
'preview_size' => 'medium',
),
),
),
),
'location' => array(
array(
array(
'param' => 'page',
'operator' => '==',
'value' => get_page_by_path(sanitize_title($option_page_title))->ID,
),
),
),
'menu_order' => -1,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => true,
'description' => '',
'show_in_rest' => 0,
) );
}
add_action( 'acf/init', 'GenerateACFOptions');
The fields are correctly Shown inside the gutenberg editor with my code. Yet, when i save draft or even publish the page and then refresh my page, everything is cleaned. I have other general fields in my website, created inside the ACF admin page, and they are working perfectly fine. When i try to use the get_fields($id_of_the_option_page);
, only the general ACF are shown, not the code generated ones.
Do you have any idea on the problem ?
Thanks for your patience, i will provide more info if needed
I have a custom post type “Client”, and a custom taxonomy “Region”. I would like to set a different “logo weight” value for each client’s region, and store it in a region_weights array.
I created a region_weights
ACF field of type “Group”, into which i want to dynamically include the sub fields (1 per region attached to the client).
define('REGION_WEIGHTS_FIELD_KEY', 'field_6668114add626');
add_filter('acf/prepare_field/key=' . REGION_WEIGHTS_FIELD_KEY, 'prepare_region_weights_field');
function prepare_region_weights_field($field)
{
global $post;
// Only apply this to the 'region_weights' field group
if ($field['_name'] !== 'region_weights' || $post->post_type !== 'client') {
return $field;
}
// Get the regions associated with this client
$regions = wp_get_post_terms($post->ID, 'region');
if (is_wp_error($regions) || empty($regions)) {
return false; // No regions, no fields to display
}
$field_value = get_post_meta($post->ID, REGION_WEIGHTS_FIELD_KEY, true);
// Generate a field for each region
foreach ($regions as $region) {
$field_name = 'field_region_weights_' . $region->term_id;
$default_value = isset($field_value[$field_name]) ? $field_value[$field_name] : 0;
$region_field = array(
'key' => $field_name,
'label' => $region->name . ' Logo Weight',
'name' => $field_name, // Use the correct field name
'type' => 'select',
'instructions' => 'How often should the ' . $region->name . ' logo appear?',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'choices' => array(
0 => 'Logo should not appear',
1 => 'Logo should appear once in a while',
2 => 'Logo should appear pretty often',
3 => 'Logo should appear most often',
),
'default_value' => $default_value,
'value' => $default_value, // Use the correctly formatted meta key for the value
'_name' => 'region_weights',
'parent' => $field['key'],
'_valid' => 1,
);
$field['sub_fields'][] = $region_field;
}
// Replace the original field with the generated fields
return $field;
}
That part works. What does not work is that i cannot save the fields. The update_field function I attached to the ‘acf/save_post’ action hook returns false and I fail to see why. Can you help ?
add_action('save_post', 'save_client_regionWeights');
function save_client_regionWeights($post_id)
{
// Check if we're saving a 'client' post type
if (get_post_type($post_id) !== 'client') {
return;
}
// Check user permissions
if (!current_user_can('edit_post', $post_id)) {
return;
}
// Check if it's an autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
// Check if ACF data is being saved
if (!isset($_POST['acf'])) {
return;
}
if (!isset($_POST['acf'][REGION_WEIGHTS_FIELD_KEY])) {
return;
}
// Get the regions associated with this client
$regions = wp_get_post_terms($post_id, 'region');
if (is_wp_error($regions) || empty($regions)) {
// No regions, nothing to save
return;
}
// Prepare an array to hold our region weights data
$region_weights_data = array();
// Loop through each region and collect the weight data from $_POST
foreach ($regions as $region) {
$field_name = 'field_region_weights_' . $region->term_id;
if (isset($_POST['acf'][REGION_WEIGHTS_FIELD_KEY][$field_name])) {
// Add this region's weight to our data array
$region_weights_data[$field_name] = $_POST['acf'][REGION_WEIGHTS_FIELD_KEY][$field_name];
} else {
// If no weight was set, default to 0
$region_weights_data[$field_name] = 0;
}
}
// Update the region weights data
update_field(REGION_WEIGHTS_FIELD_KEY, $region_weights_data, $post_id);
}
If I print the content of $_POST[‘acf’] I get sensible data:
Array
(
[field_646f1e398ee52] => Client Something
[field_63c684c9f2e59] => 95926
[field_63c93f5d38405] => 95921
[field_65cde112bc88c] => 2
[field_6668114add626] => Array
(
[field_region_weights_315] => 2
)
)
What am I doing wrong ?
Hi,
I am currently working on a few small utility applications to help move data from locally stored files to a locally hosted WordPress site. I am doing this through python-xmlrpc which has worked well up until this point.
I would like to pre-face this by saying that I do not have access to change any of the theme code or the ACF field settings within the site. I can simply create and edit posts.
The issue occurs from a post type that only really makes use of the ACF fields given to it and acts like an account database for users (which are separate to the actual WordPress users). When I attempt to create a new post of this post type, it will create a new post and the fields will end up filled but not actually saved to the database. I then need to press the “Update” or “Publish” button manually on the page which will save the data and allow it to be used (since the data acts as accounts, I have tested this by trying to log into the newly made account both before and after manually “saving” the data).
I am placing the values into the WordPressPost.custom_fields attribute (https://python-wordpress-xmlrpc.readthedocs.io/en/latest/ref/wordpress.html). To do this, I am using the field name rather than the field key which is mentioned in a few other threads. I tried to use the field key to make this work but it would make the post and not actually fill in any data at all.
Does anyone know why the post will not save just from the xmlrpc call and anyways that you can make that happen?
I understand that this could just be a limitation of ACF and XMLRPC in which case I have a couple options. One to use Selenium to just simulate the button press but this would be a much slower solution. Another thought I’ve had is to try and perform the same actions that the “Update” button does but externally through my own program. The only thing I’ve found so far is a call to admin-ajax.php, so if anyone has an idea of how that could be replicated that would be very much appreciated.
I would also like to add that editing posts of this type works perfectly as expected and can even edit the new posts before I have manually pressed “Update”. Although, the new posts will not function as accounts until I have pressed “Update” even after editing through xmlrpc.
I’m posting here to document specific behavior of ACF Pro + Polylang Pro that I ran into.
I’ve been working through an issue with the ACF relationship field that I’ve noticed back in September and has persisted through the latest updates.
Data returned for the relationship field didn’t display after save for some post types.
I have various post types (e.g. project and lecture). After saving the post their IDs are saved seemingly correct in wp_post_meta.
In wp_post_meta I saw e.g.:
a:2:{i:0;s:5:"33694";i:1;s:5:"29094";}
IDs of respectively a project and a lectureem>.
However, only certain post types would then show up after the reload of the post edit page or front-end (project shows, lecture didn’t).
They appeared to be loaded from the database incorrectly.
Digging further, it appeared this was caused by Polylang Pro.
The project post was marked for translation. The lecture post type wasn’t.
Additionally, after marking the lecture post type for translation, I then had to apply the default language to the existing posts manually (through bulk edit).
Only then would the lecture posts show in post edit and on the front-end.
In my opinion the possibility to select untranslated posts in the relationship field, that subsequently are filtered away when getting the field values, because they do not match the current language, is confusing behaviour. I’ve contacted Polylang Pro Support to let them know about this.
I’ve seen similar issues, though without details on the usage of a multilingual plugin, in:
* https://support.advancedcustomfields.com/forums/topic/relationship-data-not-saving-for-custom-post-type/ (Relationship data not saving for custom post type)
* https://support.advancedcustomfields.com/forums/topic/relationship-field-issues-with-specific-post-type (Relationship field issues with specific post type)
For more context, it appears some values for the relationship field are not saved. In this case, however, data for the relationship was saved, but the display of that data seems to be filtered by Polylang Pro, so that the saved values are incomplete or missing on reload. Wether the data is saved correctly can be checked in the wp_post_meta table as described above.
Let me know if you need any further details.
Keep up the good work!
I’m working with WooCommerce and Advanced Custom Fields (ACF) in WordPress, and I’ve encountered a peculiar issue when trying to automatically update a custom field (order_shipping_number) in a WooCommerce order. I have two different methods for updating this field when an order’s status changes to “processing”, but only one of them works, and I’m trying to understand why.
Method 1: Direct Update (Not Working) I tried a straightforward approach where I hook directly into the woocommerce_order_status_processing action and update the field using ACF’s update_field function:
add_action( 'woocommerce_order_status_processing', 'update_product_custom_field_', 10, 1 );
function update_product_custom_field_( $order_id ) {
// Generate the shipping number using the order ID
$shipping_number = 'SHIPPINGNUMBERTEST';
// Update the custom field for the shipping number
if (function_exists('update_field')) {
update_field( 'order_shipping_number', $shipping_number, $order_id );
}
}
This method seems logical, but it doesn’t update the field in the WooCommerce order.
Method 2: Using acf/save_post (Working) However, when I use a nested action hook with acf/save_post, it works:
add_action( 'woocommerce_order_status_processing', 'update_product_custom_field_');
function update_product_custom_field_( $order_id ) {
add_action('acf/save_post', 'update_shipping_number');
}
function update_shipping_number( $order_id ) {
$shipping_number = 'SHIPPINGNUMBERTEST';
update_field( 'order_shipping_number', $shipping_number, $order_id );
}
With this method, the field updates as expected.
My Question: Why does the second method using acf/save_post work, but the direct approach fails to update the field? Is there something specific about how ACF handles data saving in the context of WooCommerce orders that requires the acf/save_post hook?
Any insights or explanations would be greatly appreciated, as I’m trying to understand the underlying mechanics of ACF and WooCommerce interactions.
I inherited a site using ACF after my predecessor left my company, and I have never worked with WordPress or ACF before now.
The theme of the site I’m managing has a custom page template called single-everfi-toolkit.php, which is pulling in layouts from a field called “Content Blocks”, which is Flexible Content:
if (have_rows('content_blocks')) {
while (have_rows('content_blocks')) {
the_row();
$everfi_fc_layout = get_row_layout();
set_query_var('everfi_fc_layout',$everfi_fc_layout);
set_query_var('everfi_fc_initial_cols', 4);//NOTE: refers to the bootstrap col-#
get_template_part('includes/fc', $everfi_fc_layout); ?>
<hr/>
<?php }
}
In the Includes folder of the theme are PHP files for all the existing layouts, with the prefixes “fc-” and then the name of the layout. I Add a Test Text layout to the Field in ACF, then made the corresponding PHP file “fc-test-text.php”:
<?php
$title = get_sub_field('block_title');
$css_id = get_sub_field('css_id');
$css_class = get_sub_field('css_class');
?>
<section<?php echo($css_id ? ' id="' . $css_id .'"' : ''); ?> class="fc-test-text content-block<?php echo($css_class ? ' ' . $css_class : ''); ?>">
<?php
if($title){
echo '<h3>'.$title.'</h3>';
}
?>
<?php
if(get_sub_field('is_intro')){
the_sub_field('intro_content');
}
?>
<div class="testTextContainer">
<p><?php echo esc_html( get_field('text') ); ?></p>
</div>
</section>
I can add my Test Text layout in my Content Blocks field when editing a toolkit page, and fill out all the fields as expected. However, the content does not show on the toolkit after saving. I tested existing layouts and they show just fine. Can anyone please help me understand what I need to do to get my Test Text content to show on the page as well?
I have an ACF repeater field to collect a list of items.
According to this topic, and the official update field documentation, I have followed the structure indicated.
My code looks like this
$repeater_key = 'field_630a7a6160224';
$value = array(
array( 'field_630a7a7d60225' => $value )
);
update_field( $repeater_key, $value, $recipe_id );
This seems to work fine and I can see the info as an array in the post custom field data as shown here – https://prnt.sc/4eYgDvHkdF7i
However, the repeater itself does not update with the info – https://prnt.sc/oR6Oe3KE1ngb
How do I get this to update the repeater field correctly please? Not sure what part of this is wrong since the info is being saved to the custom field metadata.
Hi there!
I’m using a nested repeater inside a nested repeater => a list of companies containing a list of emails each. They are saved in an options page. I’m trying to update only the list of emails of a specific company via the frontend, which I managed to do with:
if(have_rows('field_64d1e8c0387f6', 'falke_amsc_options')) {
while(have_rows('field_64d1e8c0387f6', 'falke_amsc_options')) {
the_row();
$emails= get_sub_field('field_64d1e937387fa'); // 'emails'
if([condition...]) {
$counter = 0;
while($_POST["email-$counter"]) {
$newEmails[] = array( 'field_64d1e947387fb' => $_POST["email-$counter"] );
$counter++;
}
update_sub_field( 'field_64d1e937387fa', $newEmails, 'falke_amsc_options' ); // 'emails'
}
}
}
// field_64d1e8c0387f6 => 'companies' repeater
// field_64d1e937387fa => 'emails' repeater
// field_64d1e947387fb => 'email' field
Saving the new values works perfectly fine. However, my custom validation checking if any email isn’t unique isn’t triggered when saving that way. Updating the values in the backend triggers the validation normally. Not using update_sub_field()
though. Even a dummy-validation doesn’t trigger:
function falke_acf_validate_dummy( $valid, $value, $field, $input ) {
// Bail early if value is already invalid.
if( $valid !== true ) {
return $valid;
}
return __( "Don't save the values" );
} add_filter('acf/validate_value/key=field_64d1e947387fb', 'falke_acf_validate_dummy', 10, 4);
// doesn't work either
add_filter('acf/validate_value/key=field_64d1e937387fa', 'falke_acf_validate_dummy', 10, 4);
I also tried adding the filter to the repeater containing the emails instead of the email-field itself, didn’t work either. Is there anything else I need to consider? How do I trigger the validation of my e-mail-fields when updating them with update_sub_field()
?
Thanks in advance!
Hi,
Something very weird.
I made some custom functionality to make it happens the way I need, I’ll write here all the flow:
– I have created a new custom post type called event
. I also created a custom taxonomy under event
called event_type
.
– I created from GUI a field-group with tabs and in every tabs there are custom fields.
– In one of the tabs(last of them) there is a repeater and a sub-repeater.
– Inside this sub-repeater there is a group, and under this group(let’s call it specific-event
), I have SELECT field which I populate all terms from the custom taxonomy event_type
.
– I want that in the SELECT under the specific-event
, when the user picks a term, it will show custom group under specific-event
with custom fields.
So what I did:
I have created programmatically each group and set the parent
attribute to be specific-event
field key.
Each group automatically gets ‘hidden’ class.
In the JS API, I have created some logics, to detect any term select and make the correct group(I have created programmatically) to be visible.
– So far all good, the custom functionality seems to be working,
Everytime I change the term in the select under specific-event
it shows me the correct sub-group under specific-event
.
BUT, when I add lets say 7 parent rows in the parent repeater, and inside I add more 3-4 sub-rows each,
It doesnt save all… after saving I gets only 4 parent rows, and not 7. Something very very wierd.
This is the code for the custom groups:
add_action('init', function() {
if (function_exists('acf_add_local_field_group')) {
acf_add_local_field(array(
'key' => 'field_event_event',
'label' => 'נקודת עניין',
'name' => 'event__event',
'aria-label' => '',
'type' => 'select',
'choices' => array(),
'return_format' => 'array',
'ui' => 1,
'multiple' => 0,
'parent' => 'field_6441222b20c40'
));
acf_add_local_field(array(
'key' => 'field_event_time',
'label' => 'זמן',
'name' => 'event__time',
'aria-label' => '',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'taxonomy' => '',
'parent' => 'field_6441222b20c40'
));
$event_types = get_terms([
'taxonomy' => 'event_type',
'hide_empty' => false,
]);
foreach ($event_types as $event_type) {
$dynamic_fields = (!empty(TL_ACF::get_field('event-type__dynamic-fields', 'event_type_' . $event_type->term_id)) ? TL_ACF::get_field('event-type__dynamic-fields', 'event_type_' . $event_type->term_id) : array());
$field_group = array(
'key' => 'field_' . $event_type->term_id,
'label' => $event_type->name,
'name' => 'event__type-' . $event_type->term_id,
'type' => 'group',
'wrapper' => array(
'class' => 'hidden',
),
'parent' => 'field_6441222b20c40'
);
foreach ($dynamic_fields as $dynamic_field) {
$field_group['sub_fields'][] = array(
'key' => 'field_' . $dynamic_field['dynamic-fields__system-name'],
'label' => $dynamic_field['dynamic-fields__name'],
'name' => 'type-' . $event_type->term_id . '__' . $dynamic_field['dynamic-fields__system-name'],
'type' => $dynamic_field['dynamic-fields__type']['value'],
);
}
acf_add_local_field($field_group);
}
}
});
Hi all.
I’m trying to save some custom field group meta to my acf field group. I want to use this meta to further expand some logic for my wordpress theme.
I am able to get the meta field to show, But no matter what i do i do not seem to be able to save the value to my field group, Hopefully someone can point me in the correct direction.
add_filter(
'acf/field_group/additional_group_settings_tabs',
function ( $tabs ) {
$tabs['additional_settings'] = "Additional Settings";
return $tabs;
}
);
add_filter('acf/field_group/render_group_settings_tab/additional_settings', 'add_additional_settings_fields');
function add_additional_settings_fields($field_group) {
acf_render_field_wrap(array(
'label' => 'Is Component',
'type' => 'true_false',
'name' => 'is_component',
'value' => isset($field_group['is_component']) ? $field_group['is_component'] : 0,
'instructions' => 'Check this box if this Field Group belongs to a component.',
'ui' => 1, //
), 'div', 'acf-field-component-flag');
return $field_group;
}
add_filter('acf/update_field_group', 'save_additional_settings_field_group_settings', 10, 1);
function save_additional_settings_field_group_settings($field_group) {
if (isset($_POST['is_component'])) {
$field_group['is_component'] = $_POST['is_component'];
}
return $field_group;
}
Dear Support Team,
I am writing to bring a critical issue to your attention regarding the Advanced Custom Fields (ACF) repeater functionality on our website.
Problem Description:
On certain pages of our website, we have observed a troubling behavior with the ACF repeater. When attempting to save changes made within the repeater, it intermittently loses data.
Supporting Evidence:
To provide a clearer understanding of the problem, I have recorded a video demonstrating the issue. You can access the video through this link: https://www.loom.com/share/cb7a48286c544e8a979748beed99859b?sid=5c24c78c-95d0-4c28-8a61-a004c645a619
Resolution Requested:
We kindly request the support team to investigate this matter urgently and provide a thorough analysis of the root cause. Once identified, we would appreciate prompt guidance on implementing a viable solution to rectify the ACF repeater data loss issue.
If any additional information is required from our end to assist with the investigation, please do not hesitate to reach out. Me and my team stands ready to collaborate and provide any necessary details.
Thank you for your immediate attention to this matter. We look forward to a swift resolution and maintaining the high standard of service our users expect.
Best regards,
Shubham Verma
Hello, I have a problem that is giving me a headache. I used the acf_form() function to create a custom form on the front end, using a variable post-id through a GET. I thought everything had worked out, if it weren’t for the fact that the form is taking that id, and saving it somewhere else, I don’t know which, but it certainly isn’t updating the custom post with the id determined in the GET. (The strange thing is that when I change the id in the GET it changes the form, but I have no idea which post it is taking and changing as they are not the ones I wanted.)
Everything seems to work normally, with the execution of editing and saving the correct item
Here is the code used:
<?php
$postid = $_GET['postid'];
acf_form(array(
'post_id' => $postid,
'fields' => array('target','target_year'),
'submit_value' => __("Save")
));?>
Thank you for your help
Hi,
I have an acf_form located on a specific page.
When saving the form, a custom post is created :
$args = array(
'post_id' => 'new_post', // On va créer une nouvelle publication
'new_post' => array(
'post_type' => 'enquiry',
'post_status' => 'publish',
),
'field_groups' => array(3496),
);
acf_form($args);
This works fine, because that specific post type has the same fields as the form. However, how do I create a post with a separate CPT and set some of its custom fields with values contained in the submitted form?
I tried to go another way by removing ‘new_post’ altogether from $args, and using wp_insert_post in a separate function, but I didn’t succeed.
WP version : 6.2.2
ACF version : 6.1.6
CPT version: 1.13.4
I am having custom post type in my site in that i have added two ACF fields which are of type Date Time Picker. If i entered some value by choosing date and time and save, the values are cleared. It is not saving. Same for time picker field.
I’ve noticed acf adds an empty key/value pair on groups as the first record.
As an example, here’s my group of groups for cities and regions of a particular country. The JSON is at the bottom.
This dump: var_dump(get_field( 'category_info', $custom_fields_selector )['featured_items']['cities']);
(which should have a 5 records)
Will return this:
array (size=6)
'' => null // Where does this come from?
'object_1' =>
array (size=4)
'select_object_type' => string 'category' (length=8)
'taxonomy' => int 112
'article' => boolean false
'article_anchor' => string '' (length=0)
'object_2' =>
array (size=4)
'select_object_type' => string 'category' (length=8)
'taxonomy' => int 92
'article' => boolean false
'article_anchor' => string '' (length=0)
'object_3' =>
array (size=4)
'select_object_type' => string 'category' (length=8)
'taxonomy' => int 43
'article' => boolean false
'article_anchor' => string '' (length=0)
'object_4' =>
array (size=4)
'select_object_type' => string 'post' (length=4)
'taxonomy' => boolean false
'article' => int 8491
'article_anchor' => string 'Costa Blanca' (length=12)
'object_5' =>
array (size=4)
'select_object_type' => string 'post' (length=4)
'taxonomy' => boolean false
'article' => int 6975
'article_anchor' => string 'Navarra' (length=7)
I have tried re-saving the category page, change values and creating new groups. All of which result in the same behaviour.
When I had this last week I thought it was because I named some fields as single digits (get_field( 'category_info', $custom_fields_selector )['featured_items']['cities']['1']['url']
for example), but after starting a new WP installation and database, the issue persists.
JSON:
{
"key": "field_6457b347dec09",
"label": "Uitgelichte regio's en steden",
"name": "featured_items",
"aria-label": "",
"type": "group",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"layout": "block",
"sub_fields": [
{
"key": "field_6457b3ccdec0b",
"label": "Uitgelichte regio's",
"name": "regions",
"aria-label": "",
"type": "group",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"layout": "block",
"sub_fields": [
{
"key": "field_645d1d36b4c65",
"label": "Regio 1",
"name": "",
"aria-label": "",
"type": "tab",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"placement": "top",
"endpoint": 0
},
{
"key": "field_6457b437dec0c",
"label": "Regio 1",
"name": "object_1",
"aria-label": "",
"type": "group",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"layout": "block",
"sub_fields": [
{
"key": "field_6457b453dec0d",
"label": "Categorie of artikel",
"name": "select_object_type",
"aria-label": "",
"type": "select",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"choices": {
"category": "Categoriepagina",
"post": "Artikel"
},
"default_value": false,
"return_format": "",
"multiple": 0,
"allow_null": 1,
"ui": 0,
"ajax": 0,
"placeholder": ""
},
{
"key": "field_6457b4aadec0e",
"label": "Categorie",
"name": "taxonomy",
"aria-label": "",
"type": "taxonomy",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"taxonomy": "category",
"add_term": 0,
"save_terms": 0,
"load_terms": 0,
"return_format": "id",
"field_type": "select",
"allow_null": 1,
"multiple": 0
},
{
"key": "field_6457b528dec0f",
"label": "Artikel",
"name": "article",
"aria-label": "",
"type": "post_object",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"post_type": [
"post"
],
"post_status": [
"publish"
],
"taxonomy": "",
"return_format": "id",
"multiple": 0,
"allow_null": 1,
"ui": 1
},
{
"key": "field_6457b562dec10",
"label": "Naam",
"name": "article_anchor",
"aria-label": "",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"maxlength": "",
"placeholder": "",
"prepend": "",
"append": ""
}
]
},
{
"key": "field_645d1d49b4c66",
"label": "Regio 2",
"name": "",
"aria-label": "",
"type": "tab",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"placement": "top",
"endpoint": 0
},
{
"key": "field_6457b59cdec11",
"label": "Regio 2",
"name": "object_2",
"aria-label": "",
"type": "group",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"layout": "block",
"sub_fields": [
{
"key": "field_6457b59cdec15",
"label": "Categorie of artikel",
"name": "select_object_type",
"aria-label": "",
"type": "select",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"choices": {
"category": "Categoriepagina",
"post": "Artikel"
},
"default_value": false,
"return_format": "",
"multiple": 0,
"allow_null": 1,
"ui": 0,
"ajax": 0,
"placeholder": ""
},
{
"key": "field_6457b59cdec16",
"label": "Categorie",
"name": "taxonomy",
"aria-label": "",
"type": "taxonomy",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"taxonomy": "category",
"add_term": 0,
"save_terms": 0,
"load_terms": 0,
"return_format": "id",
"field_type": "select",
"allow_null": 1,
"multiple": 0
},
{
"key": "field_6457b59cdec17",
"label": "Artikel",
"name": "article",
"aria-label": "",
"type": "post_object",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"post_type": [
"post"
],
"post_status": [
"publish"
],
"taxonomy": "",
"return_format": "id",
"multiple": 0,
"allow_null": 1,
"ui": 1
},
{
"key": "field_6457b59cdec18",
"label": "Naam",
"name": "article_anchor",
"aria-label": "",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"maxlength": "",
"placeholder": "",
"prepend": "",
"append": ""
}
]
},
{
"key": "field_645d1d4ab4c67",
"label": "Regio 3",
"name": "",
"aria-label": "",
"type": "tab",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"placement": "top",
"endpoint": 0
},
{
"key": "field_6457b59ddec19",
"label": "Regio 3",
"name": "object_3",
"aria-label": "",
"type": "group",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"layout": "block",
"sub_fields": [
{
"key": "field_6457b59ddec1d",
"label": "Categorie of artikel",
"name": "select_object_type",
"aria-label": "",
"type": "select",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"choices": {
"category": "Categoriepagina",
"post": "Artikel"
},
"default_value": false,
"return_format": "",
"multiple": 0,
"allow_null": 1,
"ui": 0,
"ajax": 0,
"placeholder": ""
},
{
"key": "field_6457b59ddec1e",
"label": "Categorie",
"name": "taxonomy",
"aria-label": "",
"type": "taxonomy",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"taxonomy": "category",
"add_term": 0,
"save_terms": 0,
"load_terms": 0,
"return_format": "id",
"field_type": "select",
"allow_null": 1,
"multiple": 0
},
{
"key": "field_6457b59ddec1f",
"label": "Artikel",
"name": "article",
"aria-label": "",
"type": "post_object",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"post_type": [
"post"
],
"post_status": [
"publish"
],
"taxonomy": "",
"return_format": "id",
"multiple": 0,
"allow_null": 1,
"ui": 1
},
{
"key": "field_6457b59ddec20",
"label": "Naam",
"name": "article_anchor",
"aria-label": "",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"maxlength": "",
"placeholder": "",
"prepend": "",
"append": ""
}
]
},
{
"key": "field_645d1d4bb4c68",
"label": "Regio 4",
"name": "",
"aria-label": "",
"type": "tab",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"placement": "top",
"endpoint": 0
},
{
"key": "field_6457b5a0dec21",
"label": "Regio 4",
"name": "object_4",
"aria-label": "",
"type": "group",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"layout": "block",
"sub_fields": [
{
"key": "field_6457b5a0dec25",
"label": "Categorie of artikel",
"name": "select_object_type",
"aria-label": "",
"type": "select",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"choices": {
"category": "Categoriepagina",
"post": "Artikel"
},
"default_value": false,
"return_format": "",
"multiple": 0,
"allow_null": 1,
"ui": 0,
"ajax": 0,
"placeholder": ""
},
{
"key": "field_6457b5a0dec26",
"label": "Categorie",
"name": "taxonomy",
"aria-label": "",
"type": "taxonomy",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"taxonomy": "category",
"add_term": 0,
"save_terms": 0,
"load_terms": 0,
"return_format": "id",
"field_type": "select",
"allow_null": 1,
"multiple": 0
},
{
"key": "field_6457b5a0dec27",
"label": "Artikel",
"name": "article",
"aria-label": "",
"type": "post_object",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"post_type": [
"post"
],
"post_status": [
"publish"
],
"taxonomy": "",
"return_format": "id",
"multiple": 0,
"allow_null": 1,
"ui": 1
},
{
"key": "field_6457b5a0dec28",
"label": "Naam",
"name": "article_anchor",
"aria-label": "",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"maxlength": "",
"placeholder": "",
"prepend": "",
"append": ""
}
]
},
{
"key": "field_645d1d4cb4c69",
"label": "Regio 5",
"name": "",
"aria-label": "",
"type": "tab",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"placement": "top",
"endpoint": 0
},
{
"key": "field_6457b5a1dec29",
"label": "Regio 5",
"name": "object_5",
"aria-label": "",
"type": "group",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"layout": "block",
"sub_fields": [
{
"key": "field_6457b5a1dec2d",
"label": "Categorie of artikel",
"name": "select_object_type",
"aria-label": "",
"type": "select",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"choices": {
"category": "Categoriepagina",
"post": "Artikel"
},
"default_value": false,
"return_format": "",
"multiple": 0,
"allow_null": 1,
"ui": 0,
"ajax": 0,
"placeholder": ""
},
{
"key": "field_6457b5a1dec2e",
"label": "Categorie",
"name": "taxonomy",
"aria-label": "",
"type": "taxonomy",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"taxonomy": "category",
"add_term": 0,
"save_terms": 0,
"load_terms": 0,
"return_format": "id",
"field_type": "select",
"allow_null": 1,
"multiple": 0
},
{
"key": "field_6457b5a1dec2f",
"label": "Artikel",
"name": "article",
"aria-label": "",
"type": "post_object",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"post_type": [
"post"
],
"post_status": [
"publish"
],
"taxonomy": "",
"return_format": "id",
"multiple": 0,
"allow_null": 1,
"ui": 1
},
{
"key": "field_6457b5a1dec30",
"label": "Naam",
"name": "article_anchor",
"aria-label": "",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"maxlength": "",
"placeholder": "",
"prepend": "",
"append": ""
}
]
}
]
},
{
"key": "field_6457b5c1dec31",
"label": "Uitgelichte steden",
"name": "cities",
"aria-label": "",
"type": "group",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"layout": "block",
"sub_fields": [
{
"key": "field_645d1d97c410f",
"label": "Stad 1",
"name": "",
"aria-label": "",
"type": "tab",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"placement": "top",
"endpoint": 0
},
{
"key": "field_6457b5c1dec41",
"label": "Stad 1",
"name": "object_1",
"aria-label": "",
"type": "group",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"layout": "block",
"sub_fields": [
{
"key": "field_6457b5c1dec42",
"label": "Categorie of artikel",
"name": "select_object_type",
"aria-label": "",
"type": "select",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"choices": {
"category": "Categoriepagina",
"post": "Artikel"
},
"default_value": false,
"return_format": "",
"multiple": 0,
"allow_null": 1,
"ui": 0,
"ajax": 0,
"placeholder": ""
},
{
"key": "field_6457b5c1dec43",
"label": "Categorie",
"name": "taxonomy",
"aria-label": "",
"type": "taxonomy",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"taxonomy": "category",
"add_term": 0,
"save_terms": 0,
"load_terms": 0,
"return_format": "id",
"field_type": "select",
"allow_null": 1,
"multiple": 0
},
{
"key": "field_6457b5c1dec44",
"label": "Artikel",
"name": "article",
"aria-label": "",
"type": "post_object",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"post_type": [
"post"
],
"post_status": [
"publish"
],
"taxonomy": "",
"return_format": "id",
"multiple": 0,
"allow_null": 1,
"ui": 1
},
{
"key": "field_6457b5c2dec45",
"label": "Naam",
"name": "article_anchor",
"aria-label": "",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"maxlength": "",
"placeholder": "",
"prepend": "",
"append": ""
}
]
},
{
"key": "field_645d2e7dc4110",
"label": "Stad 2",
"name": "",
"aria-label": "",
"type": "tab",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"placement": "top",
"endpoint": 0
},
{
"key": "field_6457b5c2dec46",
"label": "Stad 2",
"name": "object_2",
"aria-label": "",
"type": "group",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"layout": "block",
"sub_fields": [
{
"key": "field_6457b5c2dec47",
"label": "Categorie of artikel",
"name": "select_object_type",
"aria-label": "",
"type": "select",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"choices": {
"category": "Categoriepagina",
"post": "Artikel"
},
"default_value": false,
"return_format": "",
"multiple": 0,
"allow_null": 1,
"ui": 0,
"ajax": 0,
"placeholder": ""
},
{
"key": "field_6457b5c2dec48",
"label": "Categorie",
"name": "taxonomy",
"aria-label": "",
"type": "taxonomy",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"taxonomy": "category",
"add_term": 0,
"save_terms": 0,
"load_terms": 0,
"return_format": "id",
"field_type": "select",
"allow_null": 1,
"multiple": 0
},
{
"key": "field_6457b5c2dec49",
"label": "Artikel",
"name": "article",
"aria-label": "",
"type": "post_object",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"post_type": [
"post"
],
"post_status": [
"publish"
],
"taxonomy": "",
"return_format": "id",
"multiple": 0,
"allow_null": 1,
"ui": 1
},
{
"key": "field_6457b5c2dec4a",
"label": "Naam",
"name": "article_anchor",
"aria-label": "",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"maxlength": "",
"placeholder": "",
"prepend": "",
"append": ""
}
]
},
{
"key": "field_645d2e7fc4111",
"label": "Stad 3",
"name": "",
"aria-label": "",
"type": "tab",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"placement": "top",
"endpoint": 0
},
{
"key": "field_6457b5c2dec4b",
"label": "Stad 3",
"name": "object_3",
"aria-label": "",
"type": "group",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"layout": "block",
"sub_fields": [
{
"key": "field_6457b5c2dec4c",
"label": "Categorie of artikel",
"name": "select_object_type",
"aria-label": "",
"type": "select",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"choices": {
"category": "Categoriepagina",
"post": "Artikel"
},
"default_value": false,
"return_format": "",
"multiple": 0,
"allow_null": 1,
"ui": 0,
"ajax": 0,
"placeholder": ""
},
{
"key": "field_6457b5c2dec4d",
"label": "Categorie",
"name": "taxonomy",
"aria-label": "",
"type": "taxonomy",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"taxonomy": "category",
"add_term": 0,
"save_terms": 0,
"load_terms": 0,
"return_format": "id",
"field_type": "select",
"allow_null": 1,
"multiple": 0
},
{
"key": "field_6457b5c2dec4e",
"label": "Artikel",
"name": "article",
"aria-label": "",
"type": "post_object",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"post_type": [
"post"
],
"post_status": [
"publish"
],
"taxonomy": "",
"return_format": "id",
"multiple": 0,
"allow_null": 1,
"ui": 1
},
{
"key": "field_6457b5c2dec4f",
"label": "Naam",
"name": "article_anchor",
"aria-label": "",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"maxlength": "",
"placeholder": "",
"prepend": "",
"append": ""
}
]
},
{
"key": "field_645d2e81c4112",
"label": "Stad 4",
"name": "",
"aria-label": "",
"type": "tab",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"placement": "top",
"endpoint": 0
},
{
"key": "field_6457b5c2dec50",
"label": "Stad 4",
"name": "object_4",
"aria-label": "",
"type": "group",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"layout": "block",
"sub_fields": [
{
"key": "field_6457b5c2dec51",
"label": "Categorie of artikel",
"name": "select_object_type",
"aria-label": "",
"type": "select",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"choices": {
"category": "Categoriepagina",
"post": "Artikel"
},
"default_value": false,
"return_format": "",
"multiple": 0,
"allow_null": 1,
"ui": 0,
"ajax": 0,
"placeholder": ""
},
{
"key": "field_6457b5c2dec52",
"label": "Categorie",
"name": "taxonomy",
"aria-label": "",
"type": "taxonomy",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"taxonomy": "category",
"add_term": 0,
"save_terms": 0,
"load_terms": 0,
"return_format": "id",
"field_type": "select",
"allow_null": 1,
"multiple": 0
},
{
"key": "field_6457b5c2dec53",
"label": "Artikel",
"name": "article",
"aria-label": "",
"type": "post_object",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"post_type": [
"post"
],
"post_status": [
"publish"
],
"taxonomy": "",
"return_format": "id",
"multiple": 0,
"allow_null": 1,
"ui": 1
},
{
"key": "field_6457b5c2dec54",
"label": "Naam",
"name": "article_anchor",
"aria-label": "",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"maxlength": "",
"placeholder": "",
"prepend": "",
"append": ""
}
]
},
{
"key": "field_645d2e82c4113",
"label": "Stad 5",
"name": "",
"aria-label": "",
"type": "tab",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"placement": "top",
"endpoint": 0
},
{
"key": "field_6457b5c2dec55",
"label": "Stad 5",
"name": "object_5",
"aria-label": "",
"type": "group",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"layout": "block",
"sub_fields": [
{
"key": "field_6457b5c2dec56",
"label": "Categorie of artikel",
"name": "select_object_type",
"aria-label": "",
"type": "select",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"choices": {
"category": "Categoriepagina",
"post": "Artikel"
},
"default_value": false,
"return_format": "value",
"multiple": 0,
"allow_null": 1,
"ui": 0,
"ajax": 0,
"placeholder": ""
},
{
"key": "field_6457b5c2dec57",
"label": "Categorie",
"name": "taxonomy",
"aria-label": "",
"type": "taxonomy",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"taxonomy": "category",
"add_term": 0,
"save_terms": 0,
"load_terms": 0,
"return_format": "id",
"field_type": "select",
"allow_null": 1,
"multiple": 0
},
{
"key": "field_6457b5c2dec58",
"label": "Artikel",
"name": "article",
"aria-label": "",
"type": "post_object",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"post_type": [
"post"
],
"post_status": [
"publish"
],
"taxonomy": "",
"return_format": "id",
"multiple": 0,
"allow_null": 1,
"ui": 1
},
{
"key": "field_6457b5c2dec59",
"label": "Naam",
"name": "article_anchor",
"aria-label": "",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"maxlength": "",
"placeholder": "",
"prepend": "",
"append": ""
}
]
}
]
}
]
}
Hello, this one has been puzzling me but it’s maybe easy to fix. I have a cloned group on my homepage with some basic fields, the fields are saving but nothing displays on the frontend unless I enable the “Prefix Field Names” option. However, I have the exact same thing on a custom post type and everything works fine.
I want to keep the same PHP structure (image attached) to reuse this block on multiple pages, so prefixing the field name isn’t really an option. Any idea why? Thanks
Video explanation: https://www.loom.com/share/2095c0748a364f3192a4165de1bbcc8f
I created several custom taxonomies for attachments post-type. With ACFPRO I added fields to add/remove terms to an uploaded media file’s custom taxonomies..
The media edit page does show the ACF fields. However when I save, the terms are not stored. The page reloads without saving anything.
The ‘save terms’ toggle is in the on position in ACF edit page.
Is there anything I can do to force the saving of terms to a custom taxonomy for media?
True/False Values Not Updating
Steps to Reproduce
Actual Result
When saving a post under the custom post type, True/False values are not updating in the database. Turning off the Stylized UI setting for True/False fields solves this problem.
Expected Result
Saving a post under the custom post type should properly store/update all True/False field values for the post in the database.
ACF Pro Version: 5.12.13
WordPress Version: 6.1.1
PHP Version: 8.0
Hi,
Here an article talks about populating a select box dynamically:
https://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/
I’m using flexible content with a select box so it’s a little bit different.
I can get the the values to load correctly, but I cant get them to save. I have tried so may variations. It looks like the issue stems from calling have_rows() during the loop.
The Following code works:
function acf_load_color_field_choices($field)
{
// // reset choices
$field['choices'] = array();
$field['choices'][1] = "one";
$field['choices'][2] = "two";
return $field;
}
add_filter('acf/load_field/key=field_63f3f71d371a8', 'acf_load_color_field_choices');
However, when I try to change it to something a little more dynamic everything breaks. Here is the code that I am currently working with.
function acf_load_color_field_choices($field)
{
// // reset choices
$field['choices'] = array();
if (have_rows('page_sections')) :
while (have_rows('page_sections')) : the_row();
$anchor_link = get_sub_field('anchor_link');
$anchor_link_sani = str_replace(" ", "", strtolower($anchor_link));
if ($anchor_link) :
$field['choices'][$anchor_link_sani] = ucwords($anchor_link);
endif;
endwhile;
endif;
return $field;
}
add_filter('acf/load_field/key=field_63f3f71d371a8', 'acf_load_color_field_choices');
Even when I loop using have_rows without loading anything, everything breaks.
I’m assuming this has something to do with accessing the loop? Why does it load correctly, but not save?
Is there anything that I can do?
Thanks.
I have a CPT called Companies. I created an ACF relationship field called user_company that gets displayed in the Users profile page.
When a user registers, I have to go in and assign them to a company. I added the ACF field to the Users page admin column but I am unable to sort it. It currently sorts based on post_id and I have no idea how to sort it by post_title.
Here is the code I have so far:
// Add columns and data to Users admin page
add_filter( 'manage_users_columns', 'manage_users_columns_new_columns' );
function manage_users_columns_new_columns( $columns ) {
$columns['user_comp any'] = 'User Company';
return $columns;
}
add_filter( 'manage_users_custom_column', 'manage_users_custom_column_new_columns', 10, 3 );
function manage_users_custom_column_new_columns( $value, $column_name, $user_id ) {
if ( $column_name == 'user_company' ) {
$user_company = get_field('user_company', 'user_' . $user_id);
$user_company_post = get_post($user_company);
if( isset( $user_company_post ) ){
return $user_company_post->post_title;
} else {
return '-';
}
}
return $value;
}
// ACF/save_post to save title of User Company as another meta_value
function save_user_company_name ( $post_id ) {
$user_company_id = get_field( 'user_company', $post_id );
if ( $user_company_id ) {
update_post_meta( $post_id, 'user_company_name', get_post_field( 'post_title', $user_company_id ) );
}
}
add_action( 'acf/save_post', 'save_user_company_name', 20 );
// Sort columns on Users admin page
add_filter( 'manage_users_sortable_columns', 'register_sortable_columns_custom', 10, 1 );
function register_sortable_columns_custom( $columns ) {
$columns['user_company'] = 'user_company';
return $columns;
}
add_action( 'pre_get_users', 'pre_get_users_sort_columns_custom' );
function pre_get_users_sort_columns_custom( $query ) {
if ( $query->get( 'orderby' ) == 'user_company' ) { // Currently sorts by post ID vs post title. Will need to add additional code: https://support.advancedcustomfields.com/forums/topic/admin-column-a-z-sorting-for-object-field/
$query->set( 'orderby', 'meta_value' );
$query->set( 'meta_key', 'user_company_name' );
}
}
I added the acf/save_post portion based on answers I have found online but I don’t know how that works. I tried saving each Company posts as well as the Users assigned to a company. But when I try to sort on the admin page, everything blanks out. I’m not sure how to get this to work.
I’m using ACF Pro and having problems when saving changes in my admin. When I update, the field goes back to how it was before I made the adjustments. I don’t know why this is happening, I’ve tried deactivating all the other plugins and running only ACF in default theme but it didn’t work. I tried duplicating the custom fields and that didn’t work either. I checked my database to see if there were duplicated rows, but everything seems fine over there.
What should I do?
Hey all,
I’m using the .editPost XMLRPC method to update my posts’ Custom Fields on WordPress and I’m having trouble getting the Relationship field data right.
When I look at the info from .getPost, I see fields like this:
<value><struct>
<member><name>id</name><value><string>369024</string></value></member>
<member><name>key</name><value><string>featured_shortcuts</string></value></member>
<member><name>value</name><value><string>a:1:{i:0;s:5:"24076";}</string></value></member>
When I pass the same serialized data back to add another post, like 4956 instead of 24076, it doesn’t accept the serialized data a:2:{i:0;s:4:"4596";i:1;s:5:"12965";}
and instead thinks the entire thing is one string, then serializes that to s:37:"a:2:{i:0;s:4:"4596";i:1;s:5:"12965";}";
.
I’m not sure what to do — is there another way to pass serialized data in? I’ve tried using "
instead of "
but that also doesn’t take properly; also using \"
doesn’t work either.
Even passing back the original a:1:{i:0;s:5:"24076";}
onto a new post doesn’t work.
Also, I am already correctly getting the id
of the value using getPost
and it seems to be saving the data and writing it even though it’s not correctly-formatted.