This solution (if ( empty( $value) worked fine for me for quite some time, but now I get a different unique ID again whenever I refresh the page. Has there been a change in WP that affects this?
Here’s my solution B.
// Style the content editor as metabox
function my_content_editor_metabox(){
if (function_exists('get_current_screen')) {
$current_screen = get_current_screen();
if ($current_screen->post_type == 'event')
my_content_editor_metabox_init(__('Description', 'my'));
}
}
add_action('acf/input/admin_footer', 'my_content_editor_metabox');
function my_content_editor_metabox_init($title){
echo
"<script type='text/javascript'>\n".
"jQuery(function($){\n".
"$(function(){\n".
"var editor = $('#postdivrich');\n".
"if (editor.length) {\n".
"editor.addClass('postbox my-content-editor');\n".
"editor.prepend('<div class=\"postbox-header\"><h2>$title</h2></div>');\n".
"}\n".
"});\n".
"});\n".
"</script>\n";
}
Styles:
#acf_after_title-sortables:has(~ #postdivrich.gpi-content-editor){
margin-bottom: 0;
}
#postdivrich.gpi-content-editor{
margin: 20px 0 0;
}
#postdivrich.gpi-content-editor .wp-editor-tools{
background: transparent;
padding-top: 0;
width: 100%;
}
#postdivrich.gpi-content-editor .wp-editor-wrap{
margin: 16px 16px 0;
}
#postdivrich.gpi-content-editor #post-status-info{
width: calc(100% - 32px);
margin: 0 16px 16px;
}
Are you adding this into the default woocommerce account dashboard?
If so you might need ‘form’ => false
So multiple forms are not rendered in the dom. ie;
<form action="{default_wc_account_url}" method="POST">
<form action="{ACF_FORM}"> // your form is creating this.
</form> // and this inside the default form.
</form>
Could it possibly a race condition with the scheduled posts? I send emails to a queue via Action Scheduler, which then sends them singly and avoids a previous problematic race condition. It may be possible to test scheduled publishing this way also.
Had the same issue. Since the Slick is modifying the DOM, it cannot work with JSX support, so you need to set it to false. In my case it looks something like this:
"supports": {
"jsx": false,
"align": ["full"],
"anchor": true,
"className": true,
"reusable": false
},
My JS is similar to the original code:
import './styles.scss';
import $ from 'jquery';
import 'slick-carousel/slick/slick.css';
import 'slick-carousel/slick/slick-theme.css';
import 'slick-carousel';
$(function() {
/**
* initializeBlock
*
* Adds custom JavaScript to the block HTML.
*
* @date 15/4/19
* @since 1.0.0
*
* @param object $block The block jQuery element.
* @param object attributes The block attributes (only available when editing).
* @return void
*/
let initializeBlock = function( $block ) {
const $slider = $block.find('.slider');
const slickSettings = {
slidesToShow: 4,
slidesToScroll: 4,
lazyLoad: 'ondemand',
dots: true,
arrows: false,
responsive: [
{
breakpoint: 1281,
settings: {
slidesToShow: 3,
slidesToScroll: 3,
},
},
{
breakpoint: 600,
settings: {
slidesToShow: 2,
slidesToScroll: 2,
},
},
],
adaptiveHeight: true,
focusOnSelect: true
}
$slider.not('.slick-initialized').slick(slickSettings);
}
// Initialize each block on page load (front end).
$('.slider').each(function() {
initializeBlock( $(this) );
});
// Initialize dynamic block preview (editor).
if( window.acf ) {
window.acf.addAction( 'render_block_preview/type=acf-plugin/slider', initializeBlock );
}
});
I know it’s the old question, but just in case someone else encounters the same issue.
This is brilliant, it works like a charm with the backticks as RichCuer mentionned.
I edited a bit of the imageUrl const if you want to put the image in the same block folder:
const preimageUrl = wp.data.select('core/blocks').getBlockType("acf/" + blockName)?.attributes?.previewImage?.default;
//Not ideal to make two const, but you get the idea, the next line write the absolute URL with the theme folder as template
const imageUrl = passed_data.templateUrl+'/blocks/'+blockName+'/'+preimageUrl;
And in the functions.php:
function enqueue_admin_scripts_and_styles() {
wp_enqueue_script('admin-scripts', get_template_directory_uri() . '/js/admin_custom.js', array('wp-blocks', 'wp-element', 'wp-hooks'), '', true);
//We use wp_localize_script to pass data
wp_localize_script( 'admin-scripts', 'passed_data', array( 'templateUrl' => get_stylesheet_directory_uri() ) );
}
add_action('admin_enqueue_scripts', 'enqueue_admin_scripts_and_styles');
Then, you can add it to the block.json:
"previewImage": {
"type": "string",
"default": "preview.jpg"
}
The simplified PHP to get a better idea:
<?php
function acf_repeater_shortcode() {
ob_start();
if (have_rows('Table')) : ?>
<table class="Table">
<tr>
<th class="Country">Chart</th>
<th class="Points">Position</th>
</tr>
<?php while (have_rows('Table')) : the_row(); ?>
<tr>
<td class="Country"><?php the_sub_field('Country'); ?></td>
<td class="Points"><?php the_sub_field('Points'); ?></td>
</tr>
<?php endwhile; ?>
</table>
<?php endif; ?>
<?php return ob_get_clean();
}
add_shortcode('Table', 'acf_repeater_shortcode');
These is more in responsive to the thread about disabling dragging only on certain items, but that thread doesn’t allow new replies. I needed to disable dragging/ordering only certain items in a flexible content field. We create these items dynamically when a post is created and want them to remain always at the top. The only solution that worked well was destroying the jQuery UI sortable instance and creating a new one. I’ll post the code for that below, but first here’s what would answer the OP’s question:
acf.addAction( 'ready_field/key=field_5f6de18aefdd9', ( field ) => {
let list = $( '.acf-flexible-content:first > .values', field.$el[0] );
list.on( 'sortcreate', ( event, ui ) => {
list.sortable( 'destroy' );
} );
} );
Here’s what I did to exclude certain items from being dragging and also from being drop targets:
acf.addAction( 'ready_field/key=field_5f6de18aefdd9', ( field ) => {
let list = $( '.acf-flexible-content:first > .values', field.$el[0] );
list.on( 'sortcreate', ( event, ui ) => {
if ( list.data( 'reinitializing-sortable' ) === true ) {
list.data( 'reinitializing-sortable', false );
return;
}
list.data( 'reinitializing-sortable', true );
list.sortable( 'destroy' );
list.sortable( {
items: '> .layout:not([data-layout="first_name"]):not([data-layout="last_name"]):not([data-layout="email"])',
handle: '> .acf-fc-layout-handle',
forceHelperSize: true,
forcePlaceholderSize: true,
scroll: true,
stop: ( event, ui ) => {
field.render();
},
update: ( event, ui ) => {
field.$input().trigger( 'change' );
}
} );
$( '> .layout[data-layout="first_name"], > .layout[data-layout="last_name"], > .layout[data-layout="email"]', list ).each( function() {
$( '.acf-fc-layout-handle', this ).css( 'cursor', 'default' );
} );
} );
} );
Technically, based on the docs, I shouldn’t have to destroy and recreate the sortable instance. I should just be able to do this:
list.sortable( 'option', 'items', '> .layout:not([data-layout="first_name"]):not([data-layout="last_name"]):not([data-layout="email"])' );
But that wouldn’t work, so instead I had to use the hacky solution above.
Good afternoon,
Same problem here with the same error.
Wordpress : 6.6.1
Elementor Pro : version 3.23.4
ACF Pro : version 6.3.5
Broadcast : 50.13
Broadcast ThirdParty : 50.11
We have created a unique template for a post category.
We have created a group of fields in ACF, including a gallery field
When we have tested to broadcast the post trough the multisite, we had the same error as you.
After some research, we have found that we must change, at the gallery field, the image return to ID, change it again to URL, to finally return to the value Array.
And after that, the gallery was displayed without error.
I think there is a bug somewhere between Elementor and ACF.
I’m not sure where I’m going wrong but I can’t seem to get it to work for me;
add_action("gform_after_submission_2", "acf_post_submission", 10, 2);
function acf_post_submission ($entry, $form) {
//if the Advanced Post Creation add-on is used, more than one post may be created for a form submission
//the post ids are stored as an array in the entry meta
$created_posts = gform_get_meta( $entry['id'], 'gravityformsadvancedpostcreation_post_id' );
foreach ( $created_posts as $post ) {
$post_id = $post['post_id'];
// Do your stuff here.
echo "<br />Post ID: " . $post_id;
$values = rgar( $entry, '11' );
echo "<br />Billing Entity: " . $values;
// get current value
$value = get_field('billing_entity', $post_id, false);
// add new id to the array
$value[] = $values;
// update the field
update_field('field_66b0d39eed031', $value, $post_id);
}
}
The relationship field doesn’t update.
Maybe it is solved.
update_field('cf_person', [], $post_ID); // reset row
$existing_values = get_field('cf_person', $post_ID);
$new_row = array(
'acf_fc_layout' => "cf_person_set",
'cf_person_text_ja' => 'Dummy Text'
);
if ($existing_values) {
$existing_values[] = $new_row;
} else {
$existing_values = array($new_row);
}
update_field('cf_person', $existing_values, $post_ID);
Just for a future example, because I found this on a search, the latest Elementor is really having major issues with the Link field in ACF — and if you are creating something for your clients Link is way better than URL ( url meaning the client would have to hard enter the correct url address ).
As stated earlier you’ll have to write a shortcode function in your theme ( function.php )…and then, unfortunately, it doesn’t seem as if the native shortcode link function works ( [acf field='my_link'] doesn’t work ).
Something like this:
function get_acf_link_url($atts) {
$atts = shortcode_atts(array(
'field' => '',
), $atts);
$url = get_field($atts['field']);
return "<a href='" . esc_url($url) . "'>" . esc_html($url) . "</a>";
}
add_shortcode('acf_link_url', 'get_acf_link_url');
And then create a html snippet ( not a Heading or a Text Field ):
<a href="[acf_link_url field='my_link']">Link</a>
Hi Izabela,
Here are a few steps to fix your ACF custom fields issue on products:
Location Rules: Ensure the field group’s location rule is set to “Post Type” is equal to “Product”.
Display Rules: Make sure there are no extra rules hiding the fields.
Theme Compatibility: Try switching to a default theme to see if that helps.
Plugin Conflicts: Deactivate other plugins to check for conflicts.
Updates: Ensure ACF and WooCommerce are up-to-date.
Screen Options: On the product edit page, check that custom fields are enabled in “Screen Options” at the top right.
Hi, I just wanted to add a note here as it’s the only thread I’m seeing about this recent usePostMeta
feature, and I was fortunate to get to discuss some of the aspects (and limitations) of its current implementation (a/o v6.3.4) with one of the plugin developers. In particular, he noted that a block with the feature enabled must be “at the top level” in the editor and, thus, not nested in another block such as a column or group. In my current project, it would be extremely useful if one could nest one of these blocks in at least a limited set of other blocks (e.g. containers such as group, cover, and columns).
I honestly think this feature is a game-changer in that it allows combining the great editor experience provided by Gutenberg with the power of ACF fields- particularly, in associating the block fields at the post level to allow for querying by field content housed in a block within the post content. I look forward to the evolution of this great feature!
If you want to manage more than one tab, I used a unique function name for each instance:
add_filter('acf/prepare_field/key=field_key', 'custom_tab_format', 20);
function custom_tab_format($field) {
if(get_field('this_field', $post->ID)) {
$field['label'] = get_field('this_field', $post->ID);
}
return $field; }
add_filter('acf/prepare_field/key=field_key', 'custom_tab_format_two', 20);
function custom_tab_format_two($field) {
if(get_field('this_field', $post->ID)) {
$field['label'] = get_field('this_field', $post->ID);
}
return $field; }
Hopefully this is helpful to others.
Hey, I came across this post whilst updating my projetcs to the new block.json registering technique.
I followed all the advice above but still my block was not showing up. I ran my block.json file through a validator which tidied it up, corrected an erroneous quote mark and then it worked!
It seems if your block.json isn’t valid or has errors, it fails silently and you never know. So double check that json and hopefully that will also help.
Hey,
Solving is a default state for posts once they’ve had a reply. It doesn’t mean anything related to our backlog as this is a community support forum.
Feature requests should be made on advancedcustomfields.com/feedback and bugs reported via the support team.
That said, this isn’t something we can fix our side. We use the WordPress provided logic here. The code sample provided above, using parse_blocks
would be incredibly inefficient to do on a production site as it’s very expensive, and you’ll be parsing the whole page twice essentially.
The way blocks render, it’s not really viable for this to possible as blocks work without awareness of each other, outside of context – but if it were to become so, it would need to be provided by Gutenberg.
I get the values of the field but now I nothing is showing as selected.
C:\wamp64\www\esmedia\wp-content\themes\ES-Live\templates\template-events.php:241:
array (size=26)
'ID' => int 244
'key' => string 'field_6699142ff52aa' (length=19)
'label' => string 'Speakers Names' (length=14)
'name' => string 'scheduled_speakers' (length=18)
'aria-label' => string '' (length=0)
'prefix' => string 'acf' (length=3)
'type' => string 'select' (length=6)
'value' =>
array (size=0)
empty
'menu_order' => int 9
'instructions' => string '' (length=0)
'required' => int 0
'id' => string '' (length=0)
'class' => string '' (length=0)
'conditional_logic' =>
array (size=1)
0 =>
array (size=1)
0 =>
array (size=3)
...
'parent' => int 150
'wrapper' =>
array (size=3)
'width' => string '' (length=0)
'class' => string '' (length=0)
'id' => string '' (length=0)
'choices' =>
array (size=179)
947 => string 'Abigail Barnes' (length=14)
1163 => string 'Abigail Barnes and Helen Rees' (length=29)
42137 => string 'Abigail Rudner' (length=14)
1002 => string 'Adam Hergenrother' (length=17)
1004 => string 'Adam Hergenrother and Hallie Warner' (length=35)
41950 => string 'Ali Pasha' (length=9)
959 => string 'Alice Scutchey' (length=14)
38242 => string 'Alicia Fairclough' (length=17)
40584 => string 'Aliina Rowe' (length=11)
2566 => string 'Amanda Johnson' (length=14)
1458 => string 'Amy McKeown' (length=11)
907 => string 'Andrea Macarie' (length=14)
1461 => string 'Andy McMenemy' (length=13)
1296 => string 'Ann Hiatt' (length=9)
1022 => string 'Anna Read' (length=9)
1745 => string 'April Stallworth' (length=16)
1753 => string 'Arini Vlotman' (length=13)
915 => string 'Atrayah Janhe' (length=13)
2565 => string 'Ayanna Castro' (length=13)
1239 => string 'Bonnie Low-Kramen' (length=17)
1006 => string 'Caitlin Limmer' (length=14)
41952 => string 'Callum Fowler' (length=13)
40313 => string 'Candice Burningham' (length=18)
2571 => string 'Carol Schulte' (length=13)
953 => string 'Carole Spiers' (length=13)
2560 => string 'Cathy Harris' (length=12)
2564 => string 'Chi Chi Okezie' (length=14)
40586 => string 'Christoffer Wahlberg' (length=20)
893 => string 'Christy Crump' (length=13)
40823 => string 'Christy Whyte' (length=13)
40624 => string 'Claire Derrick' (length=14)
40629 => string 'Clodagh Beaty' (length=13)
40461 => string 'Cody Byrns' (length=10)
3654 => string 'Corina Wenzel' (length=13)
1150 => string 'Corinne Hoisington' (length=18)
917 => string 'Cynthia Thomsen' (length=15)
1309 => string 'Cynthia Thomsen and John Shaw' (length=29)
3650 => string 'Danielle De Wulf' (length=16)
895 => string 'Danny McCubbin' (length=14)
2574 => string 'David Holland' (length=13)
983 => string 'David Lovett-Hume' (length=17)
883 => string 'Debbie Gross' (length=12)
3656 => string 'Deborah Marchand' (length=16)
885 => string 'Diana Brandl' (length=12)
911 => string 'Dinah Liversidge' (length=16)
37784 => string 'Don Harms' (length=9)
945 => string 'Donna Gilliland' (length=15)
931 => string 'Dr Veronica Cochran' (length=19)
40541 => string 'Dr. Heather Denniston' (length=21)
42875 => string 'Ed Brenac' (length=9)
40631 => string 'Em Stroud' (length=9)
1153 => string 'Emilie Wain' (length=11)
42392 => string 'Emma Easton' (length=11)
975 => string 'Emma Reynolds' (length=13)
42394 => string 'Emma Ridderstad' (length=15)
957 => string 'Eth Lloyd' (length=9)
41828 => string 'Fiona Walsh' (length=11)
1000 => string 'Hallie Warner' (length=13)
42878 => string 'Hamish Mathers-Jones' (length=20)
40637 => string 'Hana Gray' (length=9)
935 => string 'Heather Baker' (length=13)
1328 => string 'Heather Wright' (length=14)
921 => string 'Helen Monument' (length=14)
1020 => string 'Helen Rees' (length=10)
40718 => string 'Hilary Maxwell' (length=14)
1027 => string 'IMA – International Management Assistants – National Chairmen' (length=73)
1178 => string 'Jack Bradley' (length=12)
1016 => string 'Jackie Ludwig and Sean Magennis' (length=31)
1463 => string 'James Pickles' (length=13)
985 => string 'Jason Allan Scott' (length=17)
998 => string 'Jason Liem' (length=10)
38202 => string 'Jason Whaling' (length=13)
969 => string 'Jeff Lockhart' (length=13)
963 => string 'Jennifer Corcoran' (length=17)
897 => string 'Jeremy Burrows' (length=14)
42396 => string 'Jeremy Dolan' (length=12)
42194 => string 'Jessica McBride' (length=15)
873 => string 'Joan Burge' (length=10)
899 => string 'John Shaw' (length=9)
38234 => string 'Jonathan Bennett' (length=16)
22472 => string 'Julia Leibowitz' (length=15)
901 => string 'Julia Schmidt' (length=13)
42881 => string 'Julie McLellan' (length=14)
933 => string 'Julie Perrine' (length=13)
1008 => string 'Karen Nussbaum' (length=14)
1025 => string 'Kathleen Drum' (length=13)
859 => string 'Kemetia Foley' (length=13)
42037 => string 'Kristie Webber' (length=14)
40588 => string 'Kristine Valenzuela' (length=19)
881 => string 'Laura Belgrado' (length=14)
937 => string 'Laura Schwartz' (length=14)
2567 => string 'Lauren Parsons' (length=14)
42196 => string 'Lea White' (length=9)
879 => string 'Libby Moore' (length=11)
40315 => string 'Lily Shippen' (length=12)
42139 => string 'Lindsay Robinson' (length=16)
42198 => string 'Lisa Gareau' (length=11)
2562 => string 'Lisa Larson' (length=11)
40821 => string 'Lisa Nunn' (length=9)
861 => string 'Lisa Olsen' (length=10)
1302 => string 'Liz Hardwick' (length=12)
996 => string 'Liz Van Vliet' (length=13)
903 => string 'Lizebeth Koloko-Green' (length=21)
2573 => string 'Lucy Bailey' (length=11)
871 => string 'Lucy Brazier OBE' (length=16)
1194 => string 'Lucy Brazier OBE and Melissa Esquibel' (length=37)
949 => string 'Lucy Chamberlain' (length=16)
971 => string 'Maggie Jacobs' (length=13)
1456 => string 'Maria King' (length=10)
40635 => string 'Marianne Whitlock' (length=17)
863 => string 'Marie Herman' (length=12)
967 => string 'Marion Lowrence' (length=15)
919 => string 'Marlize Schneider' (length=17)
965 => string 'Marsha Egan' (length=11)
42044 => string 'Matt Martin' (length=11)
981 => string 'Matthew Want' (length=12)
977 => string 'Melba J Duncan' (length=14)
2563 => string 'Melinda Gates' (length=13)
865 => string 'Melissa Esquibel' (length=16)
41956 => string 'Melissa Peoples' (length=15)
40242 => string 'Michael Levin' (length=13)
990 => string 'Michelle Bowditch' (length=17)
22421 => string 'Mike Thomas' (length=11)
1326 => string 'Naba Ahmed' (length=10)
1186 => string 'Neil Malek' (length=10)
2570 => string 'Nekeisha Nelson' (length=15)
1012 => string 'Nick Ginsburg' (length=13)
2559 => string 'Nicky Christmas' (length=15)
more elements...
'default_value' =>
array (size=0)
empty
'return_format' => string 'array' (length=5)
'multiple' => int 1
'allow_null' => int 0
'ui' => int 0
'ajax' => int 0
'placeholder' => string '' (length=0)
'_name' => string 'scheduled_speakers' (length=18)
'_valid' => int 1
C:\wamp64\www\esmedia\wp-content\themes\ES-Live\templates\template-events.php:332:int 64
How do I get what’s been selected on the front end? In the backend I have Abigail Barnes selected and is showing as selected
Nevermind, I just figured it out.
For anyone with the same question:
After you create child/nested taxonomies via the Add New in the CPT, the Terms shows up in the main Taxonomies menu in ACF Pro.
Under Terms at the far right, there will be a number. Click on that number and it takes you to a screen where you can add/edit those child taxonomies. You have to have add at least one first or nothing shows up there.
Hope this helps someone (or maybe I was the only one who didn’t know this).
I reached out to support and I got a quick answer! The solution is here:
oy! I found the issue. It’s from when I was following the docs. I was able to track down the mystery field to the Testimonial field group that got applied to all block fields. When I inspected the element, I was able to grab the field ID and a quick find located it on that particular field group.
I found the way to fix the file field: The form html in the bootstrap modal is set from an Ajax request. At acf_form() I found the hint, that acf.do_action('append', $('#popup-id'));
must be called after an Ajax request.
With this function call in the event-listener shown.bs.modal
deleting/replacing of the file works.
Not the way I wanted it, but this will do. I would’ve preferred the way the users field shows. I ended up changing it to a multi-option select field
function populate_speakers_field_from_site_1($field) {
// Switch to Site 1
$site_1_id = 1; // Replace with your Site 1 ID
switch_to_blog($site_1_id);
// Fetch all speakers
$args = array(
'post_type' => 'speakers',
'post_status' => 'publish',
'posts_per_page' => -1
);
$speakers_query = new WP_Query($args);
// Reset choices
$field['choices'] = array();
// Loop through speakers and add to field choices
if ($speakers_query->have_posts()) {
while ($speakers_query->have_posts()) {
$speakers_query->the_post();
$field['choices'][get_the_ID()] = get_the_title();
}
wp_reset_postdata();
}
// Restore to current blog (Site 2)
restore_current_blog();
return $field;
}
add_filter('acf/load_field/name=speaker_name', 'populate_speakers_field_from_site_1');
IF anyone can figure out how to get the ‘users’ field to work though, that’d be much appreciated! Thanks
Added some error logging, and all the cpt’s are being found
function populate_users_field_with_speakers($field) {
// Switch to Site 1
$site_1_id = 1; // Replace with your Site 1 ID
switch_to_blog($site_1_id);
// Fetch all speakers
$args = array(
'post_type' => 'speakers',
'post_status' => 'publish',
'posts_per_page' => -1
);
$speakers_query = new WP_Query($args);
// Reset choices
$field['choices'] = array();
// Loop through speakers and add to field choices
if ($speakers_query->have_posts()) {
while ($speakers_query->have_posts()) {
error_log('posts found');
$speakers_query->the_post();
$field['choices'][get_the_ID()] = get_the_title();
error_log( $field['choices'][get_the_ID()]);
}
// error_log(var_dump($field['choices']));
wp_reset_postdata();
}else{
error_log('no posts found');
}
// Restore to current blog (Site 2)
restore_current_blog();
return $field;
}
add_filter('acf/load_field/name=speaker_name', 'populate_users_field_with_speakers');
found a workaround in case someone needs similar code… i show/hide field groups based on another acf field value i use in an option page:
add_filter('acf/get_field_group', 'my_change_field_group_priceinfo');
function my_change_field_group_priceinfo($group) {
if($group['title'] != 'Preisinfo') return $group;
if(!get_field("priceinfo","options)){
require_once ABSPATH . 'wp-admin/includes/template.php';
\remove_meta_box('acf-'.$group["key"], 'post', $group["position"]);
}
return $group;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.