Advertisement
Guest User

Work-Around for current_page_parent, current_page_ancestor in custom post type

a guest
May 27th, 2010
370
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. class Webeo_Portfolio {
  3.     function Webeo_Portfolio() {
  4.         // ...
  5.         add_action('template_redirect', array(&$this, 'fixWpQuery'));
  6.         add_filter('wp_insert_post_data', array(&$this, 'savePostFilter'), 99);
  7.     }
  8.    
  9.     function savePostFilter($data, $postarr = array()) {
  10.         $data = (object) $data;
  11.        
  12.         if($data->post_type == 'portfolio' && $data->post_parent == 0) {
  13.             // TODO: Automated search for PageID of portfolio-index page
  14.             $data->post_parent = 4;
  15.         }
  16.        
  17.         return (array) $data;
  18.     }
  19.    
  20.     function fixWpQuery() {
  21.         if(get_query_var('post_type') == 'portfolio') {
  22.             global $wp_query;
  23.             $wp_query->is_posts_page = true;
  24.         }
  25.     }
  26.    
  27.     // ...
  28. }
  29. ?>
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement