Advertisement
DidouS

Update Page Field for Beaver Themer Part display

Dec 17th, 2019
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.94 KB | None | 0 0
  1. add_action( 'init' , 'update_show_page_layout_setting' );
  2.  
  3. function update_show_page_layout_setting() {
  4.  
  5.     $pageids_to_check = array(
  6.                                 3235,   // add your pageid here, optionally add more pageids that also have these fields connected
  7.                                
  8.                             );
  9.  
  10.     foreach ( $pageids_to_check as $id ):
  11.  
  12.  
  13.         // if layout is already set to layout2, we can also return early
  14.         if ( get_field( 'show_this_layout' , $id ) == 'layout2' ) return;
  15.  
  16.         // check if current time is later than the set ACF field-value
  17.         // if it is, we update the show_this_layout field to display the alternate layout
  18.         // also check if auto_switch_layout_date is actually set
  19.         //
  20.         if ( get_field( 'auto_switch_layout_date' , $id ) && date( 'Ymd H:i:s' ) >= get_field( 'auto_switch_layout_date' , $id ) ) update_post_meta(  $id ,  'show_this_layout' , 'layout2' );
  21.  
  22.     endforeach;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement