Home › Forums › General Issues › Copying a site option field value to a post field › Reply To: Copying a site option field value to a post field
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.
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.