I have a custom post type set up with some ACF fields. I also have an ACF options page set up.
I'm trying to update a text field on all custom posts with a value from a text field within the options page, when the options page is updated.
Here's what I've tried:
function update_global_flash_text(){
$current_page = get_current_screen()->base;
if($current_page == 'toplevel_page_options') {
function update_global_servicing_text() {
$args = array(
'post_type' => 'custom',
'nopaging' => true,
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
update_field('servicing_flash_text', $_POST['global_servicing_offer_text']);
}
}
wp_reset_postdata();
}
if(array_key_exists('post',$_POST)){
update_global_servicing_text();
}
}
}
add_action('admin_head','update_global_flash_text');
Ideally I also want to only update the posts field if the global field value has changed.