Guest User

Untitled

a guest
Apr 21st, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 KB | None | 0 0
  1. <?php
  2.  
  3. /* MEDIA LIBRARY FILTER */
  4. add_filter('parse_query', 'node_admin_posts_filter');
  5. add_action('restrict_manage_posts', 'node_admin_posts_filter_restrict_manage_posts');
  6. function node_admin_posts_filter($wp_query)
  7. {
  8. if (is_admin() && isset($_GET['page_id']) && $_GET['page_id'] != '')
  9. {
  10. $original_query = $wp_query;
  11. $wp_query->set('post_parent', $_GET['page_id']);
  12. $wp_query = $original_query;
  13. wp_reset_postdata();
  14. }
  15. else if (is_admin() && isset($_GET['download_id']) && $_GET['download_id'] != '')
  16. {
  17. $original_query = $wp_query;
  18. $wp_query->set('post_parent', $_GET['download_id']);
  19. $wp_query = $original_query;
  20. wp_reset_postdata();
  21. }
  22. else if (is_admin() && isset($_GET['report_id']) && $_GET['report_id'] != '')
  23. {
  24. $original_query = $wp_query;
  25. $wp_query->set('post_parent', $_GET['report_id']);
  26. $wp_query = $original_query;
  27. wp_reset_postdata();
  28. }
  29. else if (is_admin() && isset($_GET['post_type']) && $_GET['post_type'] != '')
  30. {
  31. $original_query = $wp_query;
  32. $wp_query->set('post_type', $_GET['post_type']);
  33. $wp_query = $original_query;
  34. wp_reset_postdata();
  35. }
  36. }
  37. function node_admin_posts_filter_restrict_manage_posts()
  38. {
  39. global $wpdb;
  40. $screen = get_current_screen();
  41. if ($screen->id == "upload")
  42. {
  43.  
  44.  
  45.  
  46. $get_pages = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE $wpdb->posts.post_type IN ('page') AND $wpdb->posts.post_status = 'publish' ORDER BY $wpdb->posts.post_title ASC");
  47. echo '<select name="page_id">';
  48. echo '<option value="">Filter by page...</option>';
  49. $current_page = isset($_GET['page_id']) ? $_GET['page_id'] : '';
  50. foreach ($get_pages as $get_page)
  51. {
  52. $select = null;
  53. if ($current_page == $get_page->ID)
  54. {
  55. $select = ' selected="selected"';
  56. }
  57. echo '<option value="' . $get_page->ID . '" ' . $select . '>' . $get_page->post_title . '</option>';
  58. }
  59. echo '</select>';
  60.  
  61.  
  62.  
  63. $get_downloads = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE $wpdb->posts.post_type IN ('download') AND $wpdb->posts.post_status = 'publish' ORDER BY $wpdb->posts.post_date DESC");
  64. echo '<select name="download_id">';
  65. echo '<option value="">Filter by downloads...</option>';
  66. $current_download = isset($_GET['download_id']) ? $_GET['download_id'] : '';
  67. foreach ($get_downloads as $get_download)
  68. {
  69. $select = null;
  70. if ($current_download == $get_download->ID)
  71. {
  72. $select = ' selected="selected"';
  73. }
  74. echo '<option value="' . $get_download->ID . '" ' . $select . '>' . $get_download->post_title . '</option>';
  75. }
  76. echo '</select>';
  77.  
  78.  
  79.  
  80. $get_reports = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE $wpdb->posts.post_type IN ('reports') AND $wpdb->posts.post_status = 'publish' ORDER BY $wpdb->posts.post_date DESC");
  81. echo '<select name="report_id">';
  82. echo '<option value="">Filter by report...</option>';
  83. $current_report = isset($_GET['report_id']) ? $_GET['report_id'] : '';
  84. foreach ($get_reports as $get_report)
  85. {
  86. $select = null;
  87. if ($current_report == $get_report->ID)
  88. {
  89. $select = ' selected="selected"';
  90. }
  91. echo '<option value="' . $get_report->ID . '" ' . $select . '>' . $get_report->post_title . '</option>';
  92. }
  93. echo '</select>';
  94.  
  95.  
  96.  
  97. $get_types = get_post_types();
  98. echo '<select name="post_type">';
  99. echo '<option value="">Filter by type...</option>';
  100. $current_type = isset($_GET['post_type']) ? $_GET['post_type'] : '';
  101. foreach ($get_types as $get_type)
  102. {
  103. $select = null;
  104. if ($current_type == $get_type)
  105. {
  106. $select = ' selected="selected"';
  107. }
  108. echo '<option value="' . $get_type . '" ' . $select . '>' . $get_type . '</option>';
  109. }
  110. echo '</select>';
  111.  
  112.  
  113. }
  114. }
  115.  
  116. ?>
Add Comment
Please, Sign In to add comment