_reset_front_page_settings_for_post

Reset the page_on_front, show_on_front, and page_for_post settings when a linked page is deleted or trashed.

Description

_reset_front_page_settings_for_post( (int) $post_id ); 

Also ensures the post is no longer sticky.

Parameters (1)

0. $post_id (int)
The post id.

Usage

  1. if ( !function_exists( '_reset_front_page_settings_for_post' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // The post id. 
  5. $post_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = _reset_front_page_settings_for_post($post_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/post.php  
  1. function _reset_front_page_settings_for_post( $post_id ) { 
  2. $post = get_post( $post_id ); 
  3. if ( 'page' == $post->post_type ) { 
  4. /** 
  5. * If the page is defined in option page_on_front or post_for_posts,  
  6. * adjust the corresponding options. 
  7. */ 
  8. if ( get_option( 'page_on_front' ) == $post->ID ) { 
  9. update_option( 'show_on_front', 'posts' ); 
  10. update_option( 'page_on_front', 0 ); 
  11. if ( get_option( 'page_for_posts' ) == $post->ID ) { 
  12. delete_option( 'page_for_posts', 0 ); 
  13. unstick_post( $post->ID );