Ad 468 X 60

Thursday, 18 June 2015

Widgets

Change Post Page count ( All, Published, Mine, Draft, Pending) in wordpress

This script is very useful when you creating directory type website and you have to show post and page count by author in admin and user profile interface where he can manage his post and page add and edit.



I also faced this problem and i google to find this type of scrpit many more time and finaly i fond       this script from  wordpress.stackexchange.com .You can find more detail from this link.
you have to copy and paste this code in functions.php

foreach( array( 'edit-post', 'edit-page', 'edit-movie', 'upload' ) as $hook )
    add_filter( "views_$hook" , 'wpse_30331_custom_view_count', 10, 1);

function wpse_30331_custom_view_count( $views ) 
{
    global $current_screen;
    switch( $current_screen->id ) 
    {
        case 'edit-post':
            $views = wpse_30331_manipulate_views( 'post', $views );
            break;
        case 'edit-page':
            $views = wpse_30331_manipulate_views( 'page', $views );
            break;
        /*case 'edit-movie':
            $views = wpse_30331_manipulate_views( 'movie', $views );
            break;
        case 'upload':
            $views = wpse_30331_manipulate_views( 'attachment', $views );
            break; */
    }
    return $views;
}

function wpse_30331_manipulate_views( $what, $views )
{
    global $user_ID, $wpdb;

     /*if ( !current_user_can('artist') ) 
        return $views; */
    /*
     * This needs refining, and maybe a better method
     * e.g. Attachments have completely different counts 
     */

    $total = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE (post_status = 'publish' OR post_status = 'draft' OR post_status = 'pending') AND (post_author = '$user_ID'  AND post_type = '$what' ) ");
    $publish = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish' AND post_author = '$user_ID' AND post_type = '$what' ");
    $draft = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'draft' AND post_author = '$user_ID' AND post_type = '$what' ");
    $pending = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'pending' AND post_author = '$user_ID' AND post_type = '$what' ");

    /*
     * Only tested with Posts/Pages
     * - there are moments where Draft and Pending shouldn't return any value
     */
  $views['all'] = preg_replace( '/\(.+\)/U', '('.$total.')', $views['all'] ); 
    $views['publish'] = preg_replace( '/\(.+\)/U', '('.$publish.')', $views['publish'] ); 
 /*$views['draft'] = preg_replace( '/\(.+\)/U', '('.$draft.')',    $views['draft'] ); 
 $views['pending'] = preg_replace( '/\(.+\)/U', '('.$pending.')', $views['pending'] ); */
    return $views;
}

SHARE THIS POST   

  • Facebook
  • Twitter
  • Myspace
  • Google Buzz
  • Reddit
  • Stumnleupon
  • Delicious
  • Digg
  • Technorati

1 comment:

  1. Helpful text about changing page post count, could be useful!!! :) Thanks! - Hot guys

    ReplyDelete