Advertisement
mbis

Exclude draft posts

Jan 6th, 2020
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.63 KB | None | 0 0
  1. function pm_exclude_draft_posts($bool) {
  2.     global $wpdb, $permalink_manager_uris;
  3.  
  4.     //$post_ids = $wpdb->get_col("SELECT DISTINCT ID FROM {$wpdb->posts} AS p LEFT JOIN {$wpdb->postmeta} as pm ON p.ID = pm.post_ID WHERE p.post_status = 'draft' AND pm.meta_key = '_post_revision_of' ORDER BY ID DESC");
  5.     $post_ids = $wpdb->get_col("SELECT DISTINCT ID FROM {$wpdb->posts} AS p WHERE p.post_status = 'draft' ORDER BY ID DESC");
  6.  
  7.     if(!empty($post_ids)){
  8.         foreach($post_ids as $post_id) {
  9.             unset($permalink_manager_uris[$post_id]);
  10.         }
  11.     }
  12.  
  13.   return $bool;
  14. }
  15. add_filter('permalink_manager_deep_uri_detect', 'pm_exclude_draft_posts', 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement