I need to copy/mirror the value of a site option field city_name
to a field on each post npe_city_name
so that another plugin, Network Posts Extended, can use it.
[NPE’s job is to pull a list of posts from my network’s subsites and display them on the main site. NPE can display ACF fields at the post level, but it can’t do the equivalent of get_field( 'nn_city_name', 'options' )
.]
The following does most of what I want:
function my_acf_load_value( $value, $post_id, $field ) {
if ( is_string( $value ) && $value != get_field( 'nn_city_name', 'options' ) ) {
$value = get_field( 'nn_city_name', 'options' );
}
return $value;
}
// Apply to field with key "field_5f610abd75a19" AKA 'npe_nn_city_name'
add_filter( 'acf/load_value/key=field_5f610abd75a19', 'my_acf_load_value', 10, 3 );
There’s one shortcoming with the above: it requires that all the existing posts will need to be re-saved on the subsites before they will get the new npe_city_name
value.
Is there a better way?
The difference between acf/load_value
and acf/update_value
is lost on me here. They seem to be interchangeable.