responsive_II_update_page_template_meta

Update page templete meta data.

Description

responsive_II_update_page_template_meta(); 

E.g: Change from full-width-page.php to page-templates/full-width-page.php

This function only needes to be run once but it does not mater when. after_setup_theme should be fine.


Usage

  1. if ( !function_exists( 'responsive_II_update_page_template_meta' ) ) { 
  2. require_once '/includes/functions-update.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = responsive_II_update_page_template_meta(); 
  7.  

Defined (1)

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

/includes/functions-update.php  
  1. function responsive_II_update_page_template_meta() { 
  2. $args = array( 
  3. 'post_type' => 'page',  
  4. 'meta_query' => array( 
  5. array( 
  6. 'key' => '_wp_page_template',  
  7. 'value' => 'default',  
  8. 'compare' => '!=' 
  9. ); 
  10.  
  11. $query = new WP_Query( $args ); 
  12.  
  13. if ( $query->have_posts() ) { 
  14.  
  15. while ( $query->have_posts() ) { 
  16. $query->the_post(); 
  17.  
  18. $meta_value = get_post_meta( get_the_ID(), '_wp_page_template', true ); 
  19. $page_templates_dir = 'page-templates/'; 
  20. $conatins = strpos( $meta_value, $page_templates_dir ); 
  21.  
  22. if ( false === $conatins ) { 
  23. $meta_value = $page_templates_dir . $meta_value; 
  24. update_post_meta( get_the_ID(), '_wp_page_template', $meta_value ); 
  25.