SHARE
TWEET

wp admin-filter-by-week

pustakakoran Apr 22nd, 2017 (edited) 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Tip ini diperoleh dari: https://wordpress.stackexchange.com/questions/19186/filtering-posts-on-post-administration-page-by-week-number-instead-of-by-month
  2.  
  3. Tips lainnya:
  4. https://www.sitepoint.com/customized-wordpress-administration-filters/
  5.  
  6. Pastenya du functions.php pada theme
  7.  
  8. <?php
  9. /*
  10. Plugin Name: admin-filter-by-week
  11. Plugin URI: http://en.bainternet.info
  12. Description: answer to Filtering posts on Post Administration Page by Week Number instead of by Month
  13. http://wordpress.stackexchange.com/questions/19186/filtering-posts-on-post-administration-page-by-week-number-instead-of-by-month
  14. Version: 1.0
  15. Author: Bainternet
  16. Author URI: http://en.bainternet.info
  17. */
  18.  
  19. add_filter( 'parse_query', 'week_admin_posts_filter' );
  20. add_action( 'restrict_manage_posts', 'ba_admin_posts_filter_restrict_manage_posts' );
  21.  
  22. function week_admin_posts_filter( $query )
  23. {
  24.     global $pagenow;
  25.     if ( is_admin() && $pagenow=='edit.php' && isset($_GET['weekly_archive-dropdown']) && $_GET['weekly_archive-dropdown'] != '') {
  26.         $link =  $_GET['weekly_archive-dropdown'];  
  27.         //http://en.bainternet.info/?m=2011&w=22
  28.         $pos = strpos($link, '?m=');
  29.         if ($pos !== false) {
  30.             $m = substr($link, $pos + 3);
  31.             $wpos = strpos($m, '&w=');
  32.             $w = substr($m, $wpos + 3);
  33.             $m = substr($m, 0, $wpos + 3);
  34.             $query->query_vars['year'] = $m;
  35.             $query->query_vars['w'] = $w;
  36.             $query->query_vars['post_status'] = array('publish','pending','draft','future','private');
  37.         }
  38.     }
  39. }
  40.  
  41. function hack_weekly_archives($w){
  42.     $types = "IN('publish','pending','draft','future','private')";
  43.     $w = str_replace("= 'publish'",$types,$w);
  44.     return $w;
  45. }
  46.  
  47.  
  48. function ba_admin_posts_filter_restrict_manage_posts()
  49. {
  50.     add_filter('getarchives_where','hack_weekly_archives');
  51.     ?>
  52.     <select name="weekly_archive-dropdown">
  53.     <option value=""><?php echo esc_attr( __( 'Select Week' ) ); ?></option>
  54.     <?php wp_get_archives( 'type=weekly&format=option&show_post_count=1' ); ?>
  55.     </select>
  56.     <?php
  57.     remove_filter('getarchives_where','hack_weekly_archives');
  58. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top