本文整理汇总了PHP中update_post_category_cache函数的典型用法代码示例。如果您正苦于以下问题:PHP update_post_category_cache函数的具体用法?PHP update_post_category_cache怎么用?PHP update_post_category_cache使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了update_post_category_cache函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_the_category
function get_the_category($id = false)
{
global $post, $category_cache;
if (!$id) {
$id = $post->ID;
}
if (!isset($category_cache[$id])) {
update_post_category_cache($id);
}
$categories = $category_cache[$id];
if (!empty($categories)) {
sort($categories);
} else {
$categories = array();
}
return $categories;
}
示例2: get_the_category
function get_the_category($id = false) {
global $post, $category_cache;
if ( !$id )
$id = $post->ID;
if ( !isset($category_cache[$id]) )
update_post_category_cache($id);
$categories = $category_cache[$id];
if ( !empty($categories) )
sort($categories);
else
$categories = array();
return $categories;
}
示例3: get_the_category
function get_the_category($id = false)
{
global $post, $category_cache, $blog_id;
$id = (int) $id;
if (!$id) {
$id = (int) $post->ID;
}
if (!isset($category_cache[$blog_id][$id])) {
update_post_category_cache($id);
}
$categories = $category_cache[$blog_id][$id];
if (!empty($categories)) {
usort($categories, '_get_the_category_usort');
} else {
$categories = array();
}
return $categories;
}
示例4: update_post_caches
function update_post_caches(&$posts) {
global $post_cache, $category_cache, $post_meta_cache;
global $wpdb, $blog_id;
// No point in doing all this work if we didn't match any posts.
if ( !$posts )
return;
// Get the categories for all the posts
for ($i = 0; $i < count($posts); $i++) {
$post_id_array[] = $posts[$i]->ID;
$post_cache[$blog_id][$posts[$i]->ID] = &$posts[$i];
}
$post_id_list = implode(',', $post_id_array);
update_post_category_cache($post_id_list);
update_postmeta_cache($post_id_list);
}
示例5: update_post_caches
function update_post_caches(&$posts) {
global $post_cache, $category_cache, $comment_count_cache, $post_meta_cache;
global $wpdb;
// No point in doing all this work if we didn't match any posts.
if ( !$posts )
return;
// Get the categories for all the posts
for ($i = 0; $i < count($posts); $i++) {
$post_id_array[] = $posts[$i]->ID;
$post_cache[$posts[$i]->ID] = &$posts[$i];
$comment_count_cache[$posts[$i]->ID] = $posts[$i]->comment_count;
}
$post_id_list = implode(',', $post_id_array);
update_post_category_cache($post_id_list);
// Get post-meta info
if ( $meta_list = $wpdb->get_results("SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE post_id IN($post_id_list) ORDER BY post_id, meta_key", ARRAY_A) ) {
// Change from flat structure to hierarchical:
$post_meta_cache = array();
foreach ($meta_list as $metarow) {
$mpid = (int) $metarow['post_id'];
$mkey = $metarow['meta_key'];
$mval = $metarow['meta_value'];
// Force subkeys to be array type:
if ( !isset($post_meta_cache[$mpid]) || !is_array($post_meta_cache[$mpid]) )
$post_meta_cache[$mpid] = array();
if ( !isset($post_meta_cache[$mpid]["$mkey"]) || !is_array($post_meta_cache[$mpid]["$mkey"]) )
$post_meta_cache[$mpid]["$mkey"] = array();
// Add a value to the current pid/key:
$post_meta_cache[$mpid][$mkey][] = $mval;
}
}
}
示例6: update_post_caches
function update_post_caches(&$posts)
{
global $post_cache, $category_cache, $comment_count_cache, $post_meta_cache;
global $wpdb;
// No point in doing all this work if we didn't match any posts.
if (!$posts) {
return;
}
// Get the categories for all the posts
for ($i = 0; $i < count($posts); $i++) {
$post_id_list[] = $posts[$i]->ID;
$post_cache[$posts[$i]->ID] =& $posts[$i];
}
$post_id_list = implode(',', $post_id_list);
update_post_category_cache($post_id_list);
// Do the same for comment numbers
$comment_counts = $wpdb->get_results("SELECT ID, COUNT( comment_ID ) AS ccount\r\n\tFROM {$wpdb->posts}\r\n\tLEFT JOIN {$wpdb->comments} ON ( comment_post_ID = ID AND comment_approved = '1')\r\n\tWHERE ID IN ({$post_id_list})\r\n\tGROUP BY ID");
if ($comment_counts) {
foreach ($comment_counts as $comment_count) {
$comment_count_cache["{$comment_count->ID}"] = $comment_count->ccount;
}
}
// Get post-meta info
if ($meta_list = $wpdb->get_results("SELECT post_id, meta_key, meta_value FROM {$wpdb->postmeta} WHERE post_id IN({$post_id_list}) ORDER BY post_id, meta_key", ARRAY_A)) {
// Change from flat structure to hierarchical:
$post_meta_cache = array();
foreach ($meta_list as $metarow) {
$mpid = $metarow['post_id'];
$mkey = $metarow['meta_key'];
$mval = $metarow['meta_value'];
// Force subkeys to be array type:
if (!isset($post_meta_cache[$mpid]) || !is_array($post_meta_cache[$mpid])) {
$post_meta_cache[$mpid] = array();
}
if (!isset($post_meta_cache[$mpid]["{$mkey}"]) || !is_array($post_meta_cache[$mpid]["{$mkey}"])) {
$post_meta_cache[$mpid]["{$mkey}"] = array();
}
// Add a value to the current pid/key:
$post_meta_cache[$mpid][$mkey][] = $mval;
}
}
}