当前位置: 首页>>代码示例>>PHP>>正文


PHP _count_posts_cache_key函数代码示例

本文整理汇总了PHP中_count_posts_cache_key函数的典型用法代码示例。如果您正苦于以下问题:PHP _count_posts_cache_key函数的具体用法?PHP _count_posts_cache_key怎么用?PHP _count_posts_cache_key使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了_count_posts_cache_key函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: retrieveCounts

 /**
  * Retrive counts using wp_cache
  *
  * @param {String} $post_type
  * @param {Number} [$id]
  */
 private function retrieveCounts($post_type, $id = null)
 {
     if (!isset($id)) {
         $counts = array();
         foreach ((array) wp_count_posts($post_type) as $status => $count) {
             if (in_array($status, $this->whitelist) && $count > 0) {
                 $counts[$status] = (int) $count;
             }
         }
         return $counts;
     }
     global $wpdb;
     $key = 'rest-api-' . $id . '-' . _count_posts_cache_key($post_type);
     $counts = wp_cache_get($key, 'counts');
     if (false === $counts) {
         $results = $wpdb->get_results($this->buildCountsQuery($post_type, $id));
         $counts = $this->filterStatusesByWhiteslist($results);
         wp_cache_set($key, $counts, 'counts');
     }
     return $counts;
 }
开发者ID:StefanBonilla,项目名称:CoupSoup,代码行数:27,代码来源:class.wpcom-json-api-get-post-counts-v1-1-endpoint.php

示例2: _transition_post_status

/**
 * Hook for managing future post transitions to published.
 *
 * @since 2.3.0
 * @access private
 *
 * @see wp_clear_scheduled_hook()
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string  $new_status New post status.
 * @param string  $old_status Previous post status.
 * @param WP_Post $post       Post object.
 */
function _transition_post_status($new_status, $old_status, $post)
{
    global $wpdb;
    if ($old_status != 'publish' && $new_status == 'publish') {
        // Reset GUID if transitioning to publish and it is empty.
        if ('' == get_the_guid($post->ID)) {
            $wpdb->update($wpdb->posts, array('guid' => get_permalink($post->ID)), array('ID' => $post->ID));
        }
        /**
         * Fires when a post's status is transitioned from private to published.
         *
         * @since 1.5.0
         * @deprecated 2.3.0 Use 'private_to_publish' instead.
         *
         * @param int $post_id Post ID.
         */
        do_action('private_to_published', $post->ID);
    }
    // If published posts changed clear the lastpostmodified cache.
    if ('publish' == $new_status || 'publish' == $old_status) {
        foreach (array('server', 'gmt', 'blog') as $timezone) {
            wp_cache_delete("lastpostmodified:{$timezone}", 'timeinfo');
            wp_cache_delete("lastpostdate:{$timezone}", 'timeinfo');
            wp_cache_delete("lastpostdate:{$timezone}:{$post->post_type}", 'timeinfo');
        }
    }
    if ($new_status !== $old_status) {
        wp_cache_delete(_count_posts_cache_key($post->post_type), 'counts');
        wp_cache_delete(_count_posts_cache_key($post->post_type, 'readable'), 'counts');
    }
    // Always clears the hook in case the post status bounced from future to draft.
    wp_clear_scheduled_hook('publish_future_post', array($post->ID));
}
开发者ID:SayenkoDesign,项目名称:ividf,代码行数:46,代码来源:post.php

示例3: wp_count_posts

 function wp_count_posts($type = 'post', $perm = '')
 {
     global $wpdb;
     if (!post_type_exists($type)) {
         return new stdClass();
     }
     $cache_key = _count_posts_cache_key($type . '_donation', $perm);
     $counts = wp_cache_get($cache_key, 'counts');
     if (false !== $counts) {
         return $counts;
     }
     $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} ";
     $query .= "LEFT JOIN {$wpdb->postmeta} ON wp_postmeta.post_id = wp_posts.ID ";
     $query .= 'WHERE wp_postmeta.meta_key = "_is_donation" AND wp_postmeta.meta_value = 1 AND post_type = %s ';
     $query .= 'GROUP BY post_status ';
     $results = (array) $wpdb->get_results($wpdb->prepare($query, $type), ARRAY_A);
     $counts = array_fill_keys(get_post_stati(), 0);
     foreach ($results as $row) {
         $counts[$row['post_status']] = $row['num_posts'];
     }
     $counts = (object) $counts;
     wp_cache_set($cache_key . '_donation', $counts, 'counts');
     return $counts;
 }
开发者ID:Negative-Network,项目名称:woocommerce-quick-donation,代码行数:24,代码来源:wp-donation-listing-table.php

示例4: modify_wp_count_posts

 public function modify_wp_count_posts($old_status, $type, $perm = '')
 {
     global $wpdb;
     if (!post_type_exists($type)) {
         return new stdClass();
     }
     $cache_key = _count_posts_cache_key($type, $perm);
     $counts = wp_cache_get($cache_key, 'wc_qd_modified_wp_count_posts');
     if (false !== $counts) {
         return apply_filters('wc_qd_modified_wp_count_posts', $counts, $type, $perm);
     }
     $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE  ";
     $query .= " ID NOT IN (SELECT donationid FROM `" . WC_QD_TB . "`) ";
     $query .= " AND post_type = %s ";
     if ('readable' == $perm && is_user_logged_in()) {
         $post_type_object = get_post_type_object($type);
         if (!current_user_can($post_type_object->cap->read_private_posts)) {
             $query .= $wpdb->prepare(" AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))", get_current_user_id());
         }
     }
     $query .= ' GROUP BY post_status';
     $results = (array) $wpdb->get_results($wpdb->prepare($query, $type), ARRAY_A);
     $counts = array_fill_keys(get_post_stati(), 0);
     foreach ($results as $row) {
         $counts[$row['post_status']] = $row['num_posts'];
     }
     $counts = (object) $counts;
     wp_cache_set($cache_key, $counts, 'wc_qd_modified_wp_count_posts');
     return apply_filters('wc_qd_modified_wp_count_posts', $counts, $type, $perm);
 }
开发者ID:bestmazzo,项目名称:woocomerce-quick-donation,代码行数:30,代码来源:class-quick-donation-functions.php


注:本文中的_count_posts_cache_key函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。