Created
October 9, 2024 19:54
-
-
Save undfine/114fea41ca748ba029123a969ece132d to your computer and use it in GitHub Desktop.
Force Wordpress to update (and clear cache) on certain posts when other posts are updated
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** Force another page or post (like an archive) to update when any post (of post-type) is saved | |
| * @param Hook save_post_{$post_type} | |
| * @param Callback | |
| */ | |
| add_action('save_post_property', 'clear_cache_for_property_archive', 10, 2); | |
| function clear_cache_for_property_archive($post_id, $post){ | |
| $pages_to_clear = [87,91]; // list of page/post ids that should be updated | |
| foreach($pages_to_clear as $page_id){ | |
| $page = get_post($page_id, 'OBJECT'); | |
| if ( !empty($page) && is_object($page)) { | |
| wp_update_post($page); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment