Is this a feature yet? Can we trigger it from wp-cli?
<?php
if ( defined( 'WP_CLI' ) && WP_CLI && ! class_exists( 'ACF_Commands' ) ) :
/**
* ACF_Commands
*/
class ACF_Commands extends WP_CLI_Command {
/**
* Sync ACF Fields
*
* ## OPTIONS
*
* @when init
*
* @example
*
* wp acf sync
*
*/
function sync ( $args, $assoc_args ) {
// vars
$groups = acf_get_field_groups();
$sync = array();
// bail early if no field groups
if( empty( $groups ) )
return;
// find JSON field groups which have not yet been imported
foreach( $groups as $group ) {
// vars
$local = acf_maybe_get( $group, 'local', false );
$modified = acf_maybe_get( $group, 'modified', 0 );
$private = acf_maybe_get( $group, 'private', false );
// ignore DB / PHP / private field groups
if( $local !== 'json' || $private ) {
// do nothing
} elseif( ! $group[ 'ID' ] ) {
$sync[ $group[ 'key' ] ] = $group;
} elseif( $modified && $modified > get_post_modified_time( 'U', true, $group[ 'ID' ], true ) ) {
$sync[ $group[ 'key' ] ] = $group;
}
}
// bail if no sync needed
if( empty( $sync ) ) {
WP_CLI::success( "No ACF Sync Required" );
return;
}
if( ! empty( $sync ) ) { //if( ! empty( $keys ) ) {
// vars
$new_ids = array();
foreach( $sync as $key => $v ) { //foreach( $keys as $key ) {
// append fields
if( acf_have_local_fields( $key ) ) {
$sync[ $key ][ 'fields' ] = acf_get_local_fields( $key );
}
// import
$field_group = acf_import_field_group( $sync[ $key ] );
}
}
WP_CLI::success( 'ACF SYNC SUCCESS!' );
}
}
WP_CLI::add_command( 'acf', 'ACF_Commands' );
endif; // ACF_Commands
Thanks @elliot!
I knew this one was pretty rare but I just wanted to put in on your radar.
Outside of this issue ACF has been fantastic in many ways so thank-you for all the work you have done and continue to do.
If I get an easy solution running I’ll post back here but obviously I’ll just avoid the problem in the mean time.
I’m developing features locally, testing features on a dev site, then adding the updates to the production site.
I’m most cases It would appear that this is working correctly, but unfortunately the visuals are masking filters which are still being applied to the output.
I don’t think it’s correct to hit sync and get an empty dropdown with no indication why. And I certainly can’t make that mistake on the production server. Luckily I caught this on a local -> dev server update.
I’m not the developer, but I wouldn’t consider this to be a bug and find it to be expected behavior. Any location rule based on something that does not exist will need to have those things created before the field group is edited.
I agree. The filter shows on the original local site. But when on the new server without that taxonomy, the field is empty — and the filter is still applied. When you’re making more complex repeaters and flexible content it’s hard to spot a missing item.
My expectation is that, if the field syncs, and a taxonomy is missing, it should give an idicator that you need to create that taxonomy.
Works for me, SHIP IT!
Take a look at https://github.com/ericandrewlewis/wp-custom-css-per-post. CSS edits per post could get the ball rolling. Any progress @fabrizim?
Have you looked at https://gist.github.com/fabrizim/9c0f36365f20705f7f73 yet? I haven’t tried it but https://github.com/ericandrewlewis/wp-custom-css-per-post has me interested in seeing how to quickly iterate w/ACF.
I’m seeing this with Opera 32.0 on OSX as well… which right now is really annoying for entering Japanese addresses on black-buddha.com.
I’m seeing this with Opera 32.0 on OSX as well… which right now is really annoying for entering Japanese Addresses on black-buddha.com.
Great! Thanks Elliot, I’ll give that a try.
Did ACF help you out? Are you using it for http://anightinburlington.com?
[LONGSHOT…] Here is the file that may be causing the problem. Do you see any quick fixes at first glance?
https://plugins.trac.wordpress.org/browser/polylang/trunk/frontend/frontend-auto-translate.php
I removed any reference to pre_get_posts the best I could. I’ve made my theme able to drop the multilingual plugin I have activated for testing and I believe I found the issue.
ACF 5.2.X is not compatible with PolyLang Version 1.7.2.
Check out polylang/frontend/frontend-auto-translate.php; PLL_Frontend_Auto_Translate->pre_get_posts($query);
https://wordpress.org/plugins/polylang/
@mohamed, I am experiencing an issues as well since the upgrade. By any chance do you have a multilingual plugin installed? I’m using PolyLang and it definetly modifies queries.
Let me know please.
Thanks,
Jesse
Thank-you. I’m not sure how I missed update_sub_field(...)
but I did. After messing with this stuff I found a much easier solution using the get_field_object(...)
and update_field(...)
$repeater = 'tracks';
// get the object w/info and value
$rObj = get_field_object($repeater, $video_id);
$rKey = $rObj['key'];
$rValue = $rObj['value'];
// adjust the value of any object/row directly
$rValue[0]['srclang'] = 'pwnd';
// add new object/row to the repeater field
$rValue[]=array(
'label' => 'The label',
'src' => 'The src',
'srclang' => 'The srclang',
'kind' => 'captions');
// update the repeater
update_field($rKey,$rValue,$video_id);
Check out https://wordpress.org/plugins/p3-profiler/ and see if that helps you at all. There is a detailed timeline tab that can point out what might be slowing down certain pages.
For ACF specifically I haven’t found a better option than https://codex.wordpress.org/Transients_API to speed up page loads.
I think that sounds very likely. I’ll explore that idea first and let you know if I find anything.
Sorry Elliot, and thank-you for your support, but I’d rather not cross the whole NDA jazz just yet.
If I’m the only one experiencing the problem then I’ll just hold off upgrading.
When I do, I’ll try to do some more debugging to see what is getting saved and how it’s getting pulled out. Clearly something has changed in your api w/acf_get_grouped_posts & acf_get_posts in regards to the PostObject field.
I’ll keep you posted if anything changes.
Sorry, I realize this may be confusing.
Data is displayed on the front-end until I replace the plugin with 5.2.1.
At that time my Post Object fields only output null.
Consider any debug info you see coming from 5.1.8.
post_object.php line 170
5.2.1:
$groups = acf_get_grouped_posts( $args );
5.1.8:
$groups = acf_get_posts( $args );
5.2.1:
get_posts( $value ) is removed
5.1.8:
render_field()/format_value() uses $this->get_posts
5.2.1:
render_field()/format_value() uses acf_get_posts
api-helpers.php
Not sure if it makes a diff, but it looks like in your 5.2.1|acf_get_posts() you loop the product of $posts=get_posts, while in 5.1.8|$this->get_posts() you loop the $value and don’t deal with the product of get_posts.
For example, I have a custom post type that displays a video. That video is also a custom post type with custom fields. In order to associate the video with the post, I have a field called ‘video’ that is a Post Object. That way, I can just pick the video in a list to display on that post.
When I upgraded the plugin, the videos just stops showing up. When I revert the plugin, they work again. Actually, anything using a Post Object field – which there are quite a bit (Sliders, featured items…).
With 5.1.8 this will return a Post Object:
$post = get_post(60);
echo $post->post_title;
$fields = get_fields(60);
$video_post_object = $fields['video'];
$field = get_field('video', 60);
print_r($video_post_object); // WP_Post Object ( [ID] => 926 ... )
print_r($field);
In 5.2.X the video field is blank/null/whatever.
Field Name: video
Field Type: Post Object
Required: No
Filter by Post Type: Video
Filter by Taxonomy: –
Allow Null? No
Select Multiple? No
Return Format: Post Object
Conditional Logic: No
Video is one example, but all Post Objects return null with get_field/get_fields.
I should also note, the field groups are currently being setup in the admin section under the Custom Fields tab – so ACF is driving all of this.
Same problem. Looks like it’s specific to Post Object fields. While they are set in the edit screen, get_fields/get_field is returning null values.
Ignore that, I just used my original download link and I see 5.2.1. I’ll report back soon.
Do you have a link to 5.2.1? My update in WP is only showing 5.2.0.
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!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?
— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.