Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Tip ini diperoleh dari: https://wordpress.stackexchange.com/questions/19186/filtering-posts-on-post-administration-page-by-week-number-instead-of-by-month
- Tips lainnya:
- https://www.sitepoint.com/customized-wordpress-administration-filters/
- Pastenya du functions.php pada theme
- <?php
- /*
- Plugin Name: admin-filter-by-week
- Plugin URI: http://en.bainternet.info
- Description: answer to Filtering posts on Post Administration Page by Week Number instead of by Month
- http://wordpress.stackexchange.com/questions/19186/filtering-posts-on-post-administration-page-by-week-number-instead-of-by-month
- Version: 1.0
- Author: Bainternet
- Author URI: http://en.bainternet.info
- */
- add_filter( 'parse_query', 'week_admin_posts_filter' );
- add_action( 'restrict_manage_posts', 'ba_admin_posts_filter_restrict_manage_posts' );
- function week_admin_posts_filter( $query )
- {
- global $pagenow;
- if ( is_admin() && $pagenow=='edit.php' && isset($_GET['weekly_archive-dropdown']) && $_GET['weekly_archive-dropdown'] != '') {
- $link = $_GET['weekly_archive-dropdown'];
- //http://en.bainternet.info/?m=2011&w=22
- $pos = strpos($link, '?m=');
- if ($pos !== false) {
- $m = substr($link, $pos + 3);
- $wpos = strpos($m, '&w=');
- $w = substr($m, $wpos + 3);
- $m = substr($m, 0, $wpos + 3);
- $query->query_vars['year'] = $m;
- $query->query_vars['w'] = $w;
- $query->query_vars['post_status'] = array('publish','pending','draft','future','private');
- }
- }
- }
- function hack_weekly_archives($w){
- $types = "IN('publish','pending','draft','future','private')";
- $w = str_replace("= 'publish'",$types,$w);
- return $w;
- }
- function ba_admin_posts_filter_restrict_manage_posts()
- {
- add_filter('getarchives_where','hack_weekly_archives');
- ?>
- <select name="weekly_archive-dropdown">
- <option value=""><?php echo esc_attr( __( 'Select Week' ) ); ?></option>
- <?php wp_get_archives( 'type=weekly&format=option&show_post_count=1' ); ?>
- </select>
- <?php
- remove_filter('getarchives_where','hack_weekly_archives');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement