@bobz I’m assuming WPMS means Multisite? Not a fan personally and not using it for years, but AFAIK it should work the same way, added once on a network level, activated for all sites. If muplugins_loaded
doesn’t work for you for some reason, try plugins_loaded
instead.
However, muplugins_loaded
should run. See here: https://core.trac.wordpress.org/browser/tags/5.0.3/src/wp-settings.php#L295
Does you mu-plugin have a proper plugin header comment? If add_option()
doesn’t work as well, I suspect your code isn’t running at all.
@tusca95 You’re apparently developing without error reporting turned on. Your code throws multiple (E_NOTICE) Undefined index: notices for $instance[‘title’] and $instance[‘sponsors’] usage.
$instance['sponsors'] = strip_tags( $new_instance['sponsors'] );
In this line, you expect $instance[‘sponsors’], but that’s not how ACF sends the data, I suppose. Please, turn on error reporting and debug the incoming request first.
@tusca95 Please provide the full code so I can check it locally.
@psymeons you’re welcome 🙂
The gallery field is stored in the database as a serialized array of attachment IDs.
You can use native WordPress’ function to get those IDs in a form of simple one-dimensional array:
get_post_meta( $post_id, 'gallery_field_key', true )
Some functions in this context may require a $post_id
passed as param, at least have_rows()
and get_field()
, e.g.:
while ( have_rows( 'sponsors', 'widget_gallerysponsor_widget' ) ) : the_row();
In your case the location is set to widget, so the $post_id
value should be widget_{$widget_id}
. See this documentation page for details.
@bigskillet Well, yes and no. They are updatable, unless you’ve disabled plugin updates via wp-config constant or have incorrect user:group settings on the server. However, if you have an automated deployment routine that runs composer install
– those admin updates will be overwritten.
@bigskillet if you’re installing it as a “library”, it will be installed in vendor
dir. The ACF plugin itself doesn’t utilize namespaces and autoloading so it’ll just sit there, doing nothing.
It won’t be activated as a WordPress plugin, you need to load the library yourself and hook it into WordPress’ lifecycle + configure some internal ACF settings. You can do it in a form of plugin / mu-plugin or in functions.php. I prefer using muplugins_loaded
hook instead of plugins_loaded
to make sure ACF Pro is loaded before any plugins that rely on it:
define( 'ACF_PATH', 'vendor/advanced-custom-fields/advanced-custom-fields-pro/' );
define( 'ACF_ABSPATH', '/absolute/path/to/project/' . ACF_PATH );
/**
* Load ACF plugin as library managed by Composer.
*/
function load_acf_library()
{
require_once ACF_ABSPATH . '/acf.php';
}
add_action( 'muplugins_loaded', 'load_acf_library' );
/**
* Configure ACF Settings in bulk.
*/
function acf_settings()
{
// Absolute path to ACF plugin folder including trailing slash
acf_update_setting( 'path', ACF_ABSPATH );
// URL to ACF plugin folder including trailing slash
acf_update_setting( 'dir', home_url( '/' ) . ACF_PATH );
}
add_filter( 'acf/init', 'acf_settings' );
In case someone lands here, couple updates as of early 2019:
The quicktags_settings
filter accepts 2 params, and that second one is $editor_id
. Default value for native WP editor is content
. ACF editor field, unsurprisingly, has the value of acf_content
.
function filter_editor_quicktags( $qtInit, $editor_id )
{
if ( $editor_id === 'acf_content' ) {
$qtInit['buttons'] = 'strong,em,block';
}
return $qtInit;
}
add_filter( 'quicktags_settings', 'filter_editor_quicktags', 10, 2 );
Haven’t checked it with PHP 7 yet, however it works fine with the latest HHVM 🙂
Cool! Happy to help)
Did some tests and found out it was get_fields();
function causing this amount of queries. This is a bit confusing behavior. Reading documentation, I expected this function to do smth like SELECT * FROM wp_postmeta WHERE post_id = $ID
. One query, run only once and cache results. The post_id
column is index so it would be fast even with millions of rows. Just tested it – takes 0.0005s to complete, returns ALL custom fields associated with post, each ACf field twice – with and without underscore. Instead, it looks like this function gets all keys and runs a separate query for every key to get its value.
In documentation there’s a recommendation to use this function if:
…if you have a large amount of fields which you would prefer not to code independently.
If this function produces hundreds of queries, using it with large amount of fields will be a suicide.
Am I still getting this wrong?
Hey @WazzaJB
That was the first thing we tried. We thought it will be a huge list to work with – 195 countries with thousands of cities. And just for the sake of easier to use UI we decided to go with ACF. At first, it sounded cool. But now we’re noticing a significant performance hit with this queries. So, yes. We are going to reconsider using WP taxonomies.
Anyway, ACF has several relational fields and making queries like this might be pretty usual. It would be great to hear from Elliot and see if there’s another, better way of doing this.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.