Advertisement
mbis

Exclude draft posts

Feb 27th, 2020
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.64 KB | None | 0 0
  1. function pm_exclude_drats($element_id, $uri_parts) {
  2.     global $permalink_manager_uris;
  3.  
  4.     if(is_numeric($element_id) && !empty($uri_parts['uri'])) {
  5.         while(empty($new_element_id)) {
  6.             $post_id = (int) $element_id;
  7.             $post = get_post($post_id);
  8.  
  9.             if($post->post_status == 'draft') {
  10.                 $uri = $uri_parts['uri'];
  11.                 unset($permalink_manager_uris[$post_id]);
  12.  
  13.                 $element_id = array_search($uri, $permalink_manager_uris);
  14.             } else {
  15.                 $new_element_id = $element_id;
  16.             }
  17.         }
  18.     }
  19.  
  20.     return (!empty($new_element_id)) ? $new_element_id : $element_id;
  21. }
  22. add_action('permalink_manager_detected_element_id', 'pm_exclude_drats', 99, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement