Guest User

Work-Around for current_page_parent, current_page_ancestor in custom post type

a guest
May 27th, 2010
256
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. ?>
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×