I am really making a huge use of ACF's options pages and repeater fields. In order to reduce the amount of queries (from about 500 to 80) I'm caching some field outputs with the help of Wordpress Transient API.
I know the hook for ACF options pages is:
add_action( 'acf/save_post', 'reference_function') );
But the problem for me is, that I have multiple options pages. And I don't want all my functions to run when any options page is saved…
These are my current options pages
add_filter('acf/options_page/settings', 'my_acf_options_page_settings');
if(function_exists("register_options_page")) {
acf_add_options_page();
register_options_page('Spielübersicht');
register_options_page('Mannschaft');
register_options_page('SCHWALBE arena TV');
register_options_page('Sponsoren');
register_options_page('Werbung');
register_options_page('Einstellung');
register_options_page('Fanclubs');
register_options_page('Sidebar');
}
Is there a way to filter the action so that my transients are only created when the related options page is saved?
Adding the Options page The code above instructs WordPress to call the create_theme_options_page function, which adds the page to the Settings section of the WordPress dashboard. The add_options_page function requires a handful of parameters: $page_title : the title of the page. $menu_title : the name of the menu.
Luckily I was able to solve my problem! Have a look at my code in the plugins’ support forum: http://support.advancedcustomfields.com/forums/topic/acfsave_post-for-specific-options-page/
function clear_advert_main_transient() {
$screen = get_current_screen();
if (strpos($screen->id, "acf-options-adverts") == true) {
delete_transient('advert_main_transient1');
delete_transient('advert_main_transient2');
delete_transient('advert_main_transient3');
}
}
add_action('acf/save_post', 'clear_advert_main_transient', 20);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With