RCCWP_CustomWritePanel::GetCountPstWritePanel PHP Method

GetCountPstWritePanel() public static method

public static GetCountPstWritePanel ( $write_panel_id )
    public static function GetCountPstWritePanel($write_panel_id)
    {
        global $wpdb;
        $user = wp_get_current_user();
        $sql = $wpdb->prepare("SELECT COUNT(DISTINCT(p.ID)) AS num_posts, p.post_status FROM {$wpdb->posts} p JOIN {$wpdb->postmeta} pm  ON p.id = pm.post_id WHERE meta_key = %s AND meta_value = %s GROUP BY p.post_status", array("_mf_write_panel_id", $write_panel_id));
        $count = $wpdb->get_results($sql, ARRAY_A);
        $stats = array('publish' => 0, 'private' => 0, 'draft' => 0, 'pending' => 0, 'future' => 0, 'trash' => 0);
        foreach ((array) $count as $row_num => $row) {
            $stats[$row['post_status']] = $row['num_posts'];
        }
        $stats = (object) $stats;
        return $stats;
    }

Usage Example

コード例 #1
0
function change_number_manage($where)
{
    global $wpdb, $parent_file;
    if (isset($_SESSION['change_number_manage'])) {
        return $where;
    }
    $types = array('edit.php', 'edit-pages.php', 'edit.php?post_type=page');
    if (!in_array($parent_file, $types)) {
        return $where;
    }
    if (isset($_GET['custom-write-panel-id'])) {
        if (is_wp30()) {
            $ver = '30';
            $post_type = 'post';
            if (isset($_GET['post_type'])) {
                $post_type = $_GET['post_type'];
            }
        } else {
            $ver = '29';
            $post_type = $parent_file;
        }
        $num_posts_mf = RCCWP_CustomWritePanel::GetCountPstWritePanel($_GET['custom-write-panel-id']);
        printf("\n      <script type=\"text/javascript\">\n      //<![CDATA[\n        jQuery().ready(function() {\n          change_number_manage_wp%s('(%s)','(%s)','(%s)','(%s)','(%s)','(%s)','(%s)','%s','filter-posts=1&custom-write-panel-id=%s');\n        });\n      //]]>\n      </script>", $ver, array_sum((array) $num_posts_mf) - $num_posts_mf->trash, $num_posts_mf->publish, $num_posts_mf->pending, $num_posts_mf->draft, $num_posts_mf->private, $num_posts_mf->trash, $num_posts_mf->future, $post_type, $_GET['custom-write-panel-id']);
        $_SESSION['change_number_manage'] = "1";
    }
    return $where;
}