Advertisement
Konark

Untitled

Mar 14th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. <?php
  2. function cmsmasters_options_reinit_run() {
  3.     $atts = array(
  4.         array(
  5.             'cmsmasters_post_type' => 'page',
  6.             'cmsmasters_meta' => array(
  7.                 'cmsmasters_heading_height' => "323"
  8.             )
  9.         )
  10.     );
  11.    
  12.     cmsmasters_options_reinit($atts);
  13. }
  14.  
  15. add_action('init', 'cmsmasters_options_reinit_run');
  16.  
  17.  
  18. function cmsmasters_options_reinit($atts) {
  19.     foreach ($atts as $attr) {
  20.         $query = new WP_Query(array(
  21.             'post_type' => $attr['cmsmasters_post_type'],
  22.             'posts_per_page' => -1
  23.         ));
  24.        
  25.         if ($query->have_posts()) {
  26.             while ($query->have_posts()) {
  27.                 $query->the_post();
  28.                
  29.                
  30.                 foreach ($attr['cmsmasters_meta'] as $meta_key => $new_meta) {
  31.                     $old_meta = get_post_meta(get_the_ID(), $meta_key, true);
  32.                    
  33.                     if (isset($new_meta) && $new_meta !== $old_meta) {
  34.                         update_post_meta(get_the_ID(), $meta_key, $new_meta);
  35.                     }
  36.                 }
  37.             }
  38.         }
  39.        
  40.         wp_reset_postdata();
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement