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;
}
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;
}
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;
}
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);
}
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;
		}
	}
}
Exemplo n.º 6
0
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;
        }
    }
}