Support

Account

Home Forums Add-ons Options Page acf/save_post for specific options page Reply To: acf/save_post for specific options page

  • I found a solution after reading this post: http://support.advancedcustomfields.com/forums/topic/when-using-save_post-action-how-do-you-identify-which-options-page/

    While using WP get_current_screen()-function you can check if the ID in the output-array contains the slug of your specific option page.
    http://codex.wordpress.org/Function_Reference/get_current_screen

    For example you have an options page called “adverts” and want run the function mentioned above when you save this specific option 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);

    Now WP Transients make even more fun and will save you tons of queries if you have complex acf-fields and loops! 🙂