Skip to content

Instantly share code, notes, and snippets.

@undfine
Created October 9, 2024 19:54
Show Gist options
  • Select an option

  • Save undfine/114fea41ca748ba029123a969ece132d to your computer and use it in GitHub Desktop.

Select an option

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
/** 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