本文整理汇总了PHP中update_post_cache函数的典型用法代码示例。如果您正苦于以下问题:PHP update_post_cache函数的具体用法?PHP update_post_cache怎么用?PHP update_post_cache使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了update_post_cache函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: update_post_caches
/**
* Call major cache updating functions for list of Post objects.
*
* @package WordPress
* @subpackage Cache
* @since 1.5.0
*
* @uses $wpdb
* @uses update_post_cache()
* @uses update_object_term_cache()
* @uses update_postmeta_cache()
*
* @param array $posts Array of Post objects
* @param string $post_type The post type of the posts in $posts. Default is 'post'.
* @param bool $update_term_cache Whether to update the term cache. Default is true.
* @param bool $update_meta_cache Whether to update the meta cache. Default is true.
*/
function update_post_caches(&$posts, $post_type = 'post', $update_term_cache = true, $update_meta_cache = true)
{
// No point in doing all this work if we didn't match any posts.
if (!$posts) {
return;
}
update_post_cache($posts);
$post_ids = array();
foreach ($posts as $post) {
$post_ids[] = $post->ID;
}
if (empty($post_type)) {
$post_type = 'post';
}
if ($update_term_cache) {
if (is_array($post_type)) {
$ptypes = $post_type;
} elseif ('any' == $post_type) {
// Just use the post_types in the supplied posts.
foreach ($posts as $post) {
$ptypes[] = $post->post_type;
}
$ptypes = array_unique($ptypes);
} else {
$ptypes = array($post_type);
}
if (!empty($ptypes)) {
update_object_term_cache($post_ids, $ptypes);
}
}
if ($update_meta_cache) {
update_postmeta_cache($post_ids);
}
}
开发者ID:BGCX261,项目名称:zombie-craft-svn-to-git,代码行数:51,代码来源:post.php
示例2: update_page_cache
/**
* Alias of update_post_cache().
*
* @see update_post_cache() Posts and pages are the same, alias is intentional
*
* @since 1.5.1
* @deprecated 3.4.0
*
* @param array $pages list of page objects
*/
function update_page_cache(&$pages)
{
_deprecated_function(__FUNCTION__, '3.4', 'update_post_cache()');
update_post_cache($pages);
}
开发者ID:rkglug,项目名称:WordPress,代码行数:15,代码来源:deprecated.php
示例3: BuildSitemap
//.........这里部分代码省略.........
$where .= ") ";
$where .= " AND post_password='' ORDER BY post_modified DESC";
$sql .= $where;
if ($this->GetOption("b_max_posts") > 0) {
$sql .= " LIMIT 0," . $this->GetOption("b_max_posts");
}
$postCount = intval($wpdb->get_var("SELECT COUNT(*) AS cnt FROM `" . $wpdb->posts . "` WHERE " . $where, 0, 0));
//Create a new connection because we are using mysql_unbuffered_query and don't want to disturb the WP connection
//Safe Mode for other plugins which use mysql_query() without a connection handler and will destroy our resultset :(
$con = $postRes = null;
if (true) {
$postRes = mysql_query($sql, $wpdb->dbh);
if (!$postRes) {
trigger_error("MySQL query failed: " . mysql_error(), E_USER_NOTICE);
//E_USER_NOTICE will be displayed on our debug mode
return;
}
}
if ($postRes) {
$prioProvider = NULL;
$z = 1;
$zz = 1;
//Default priorities
$default_prio_posts = $this->GetOption('pr_posts');
$default_prio_pages = $this->GetOption('pr_pages');
//Change frequencies
$cf_pages = $this->GetOption('cf_pages');
$cf_posts = $this->GetOption('cf_posts');
$minPrio = $this->GetOption('pr_posts_min');
//Cycle through all posts and add them
while ($post = mysql_fetch_object($postRes)) {
//Fill the cache with our DB result. Since it's incomplete (no text-content for example), we will clean it later.
$cache = array(&$post);
update_post_cache($cache);
//Set the current working post for other plugins which depend on "the loop"
$GLOBALS['post'] =& $post;
$permalink = get_permalink($post->ID);
if ($permalink != $home && $post->ID != $homePid) {
$isPage = false;
if ($wpCompat) {
$isPage = $post->post_status == 'static';
} else {
$isPage = $post->post_type == 'page';
}
//Default Priority if auto calc is disabled
$prio = 0;
if ($isPage) {
//Priority for static pages
$prio = $default_prio_pages;
} else {
//Priority for normal posts
$prio = $default_prio_posts;
}
if (!$isPage && $minPrio > 0 && $prio < $minPrio) {
$prio = $minPrio;
}
//Add it
$this->AddUrl($permalink, $this->GetTimestampFromMySql($post->post_modified_gmt && $post->post_modified_gmt != '0000-00-00 00:00:00' ? $post->post_modified_gmt : $post->post_date_gmt), $isPage ? $cf_pages : $cf_posts, $prio);
if (false) {
$subPage = '';
for ($p = 1; $p <= $post->postPages; $p++) {
if (get_option('permalink_structure') == '') {
$subPage = $permalink . '&paged=' . ($p + 1);
} else {
$subPage = trailingslashit($permalink) . user_trailingslashit($p + 1, 'single_paged');
}
开发者ID:shimion,项目名称:stlucks,代码行数:67,代码来源:SEO.php
示例4: posts
/**
* Adds posts and pages to the sitemap.
*
* @since 1.3
*/
protected function posts()
{
global $wpdb;
$post_type = $this->get_info('content_type');
$post_type_is_page = $post_type == 'page';
$post_type_is_post = $post_type == 'post';
if (!($post_type_is_post || $post_type_is_page)) {
return false;
}
$post_ids = $post_attachments = array();
$post_not_in = '';
$limit = $this->getLimit();
$exclude = $this->db->getOption($this->sitemap_type, array(), 'exclude');
if ($exclude && ($ids = wp_parse_id_list($exclude))) {
$post_not_in = 'ID NOT IN (' . implode(',', $ids) . ') AND';
}
if ($post_type_is_page) {
$this->pageForPosts = (int) get_option('page_for_posts');
}
// We retrieve a few more fields than needed to make get_permalink() work properly
$posts = $wpdb->get_results("SELECT ID, post_date, post_status, post_name, post_modified, post_parent, post_type\n\t\t\t FROM {$wpdb->posts}\n\t\t\t WHERE {$post_not_in} post_type = '{$post_type}' AND post_status = 'publish' AND post_password = ''\n\t\t\t ORDER BY post_modified DESC\n\t\t\t LIMIT {$limit}");
if (!$posts) {
return false;
}
foreach ($posts as $index => $post) {
$post = sanitize_post($post, 'raw');
$post_ids[] = $post->ID;
}
if ($post_type_is_post && $this->blog) {
$this->blog->post_modified = $posts[0]->post_modified;
}
if ($this->db->getOption('images', true)) {
$ids = implode(',', $post_ids);
$attachments = $wpdb->get_results("SELECT ID, post_title, post_content, post_excerpt, post_parent, post_type\n\t\t\t\t FROM {$wpdb->posts}\n\t\t\t\t WHERE post_parent IN ({$ids}) AND post_type = 'attachment' AND post_mime_type LIKE 'image/%'\n\t\t\t\t ORDER BY post_modified DESC");
if ($attachments) {
$this->isImageSitemap = true;
foreach ($attachments as $attachment) {
$attachment = sanitize_post($attachment, 'raw');
$post_ids[] = $attachment->ID;
$post_attachments[$attachment->post_parent][] = $attachment;
}
update_post_cache($attachments);
}
}
// Retrieves and stores into the cache the metadata we need later
update_meta_cache('post', $post_ids);
// This hack lets us save a lot of queries that would be performed when we call get_permalink()
update_post_cache($posts);
$changefreq = $this->get_info('changefreq');
$priority = $this->get_info('priority');
foreach ($posts as $post) {
$images = null;
if (isset($post_attachments[$post->ID])) {
$images =& $post_attachments[$post->ID];
}
if ($post->ID == $this->pageOnFront) {
$this->home = $post;
$this->home->images = $images;
continue;
} elseif ($post->ID == $this->pageForPosts) {
$this->blog = $post;
$this->blog->changefreq = $changefreq;
$this->blog->priority = $priority;
$this->blog->images = $images;
continue;
}
$this->addUrlItem(get_permalink($post), $post->post_modified, $this->db->getPostMeta($post->ID, 'changefreq', $changefreq), $this->db->getPostMeta($post->ID, 'priority', $priority), $images);
}
}
开发者ID:MarkSpencerTan,项目名称:webdev,代码行数:74,代码来源:sitetree-xml-factory.class.php
示例5: update_post_caches
/**
* Call major cache updating functions for list of Post objects.
*
* @package WordPress
* @subpackage Cache
* @since 1.5.0
*
* @uses $wpdb
* @uses update_post_cache()
* @uses update_object_term_cache()
* @uses update_postmeta_cache()
*
* @param array $posts Array of Post objects
* @param string $post_type The post type of the posts in $posts. Default is 'post'.
* @param bool $update_term_cache Whether to update the term cache. Default is true.
* @param bool $update_meta_cache Whether to update the meta cache. Default is true.
*/
function update_post_caches(&$posts, $post_type = 'post', $update_term_cache = true, $update_meta_cache = true)
{
// No point in doing all this work if we didn't match any posts.
if (!$posts) {
return;
}
update_post_cache($posts);
$post_ids = array();
foreach ($posts as $post) {
$post_ids[] = $post->ID;
}
if (empty($post_type)) {
$post_type = 'post';
}
if (!is_array($post_type) && 'any' != $post_type && $update_term_cache) {
update_object_term_cache($post_ids, $post_type);
}
if ($update_meta_cache) {
update_postmeta_cache($post_ids);
}
}
开发者ID:owaismeo,项目名称:wordpress-10,代码行数:38,代码来源:post.php
示例6: update_post_caches
/**
* update_post_caches() - Call major cache updating functions for list of Post objects.
*
* @package WordPress
* @subpackage Cache
* @since 1.5
*
* @uses $wpdb
* @uses update_post_cache()
* @uses update_object_term_cache()
* @uses update_postmeta_cache()
*
* @param array $posts Array of Post objects
*/
function update_post_caches(&$posts)
{
// No point in doing all this work if we didn't match any posts.
if (!$posts) {
return;
}
update_post_cache($posts);
$post_ids = array();
for ($i = 0; $i < count($posts); $i++) {
$post_ids[] = $posts[$i]->ID;
}
update_object_term_cache($post_ids, 'post');
update_postmeta_cache($post_ids);
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:28,代码来源:post.php
示例7: load_posts
/**
* Load all posts with one query, to prime the cache
*
* @see get_post()
* @since 1.0.0
*
* @param array $all_post_ids List of Post IDs
* @param bool $update_meta_cache Whether to update the Post Meta Cache (for table options and visibility)
*/
public function load_posts(array $all_post_ids, $update_meta_cache = true)
{
global $wpdb;
// Split post loading, to save memory
$offset = 0;
$length = 100;
// 100 posts at a time
$number_of_posts = count($all_post_ids);
while ($offset < $number_of_posts) {
$post_ids = array_slice($all_post_ids, $offset, $length);
$post_ids = _get_non_cached_ids($post_ids, 'posts');
// Don't load posts that are in the cache already
if (!empty($post_ids)) {
$post_ids_list = implode(',', $post_ids);
$posts = $wpdb->get_results("SELECT {$wpdb->posts}.* FROM {$wpdb->posts} WHERE ID IN ({$post_ids_list})");
update_post_cache($posts);
if ($update_meta_cache) {
update_meta_cache('post', $post_ids);
// get all post meta data for all table posts, @see get_post_meta()
}
}
$offset += $length;
// next array_slice() $offset
}
}
开发者ID:heyjones,项目名称:crossfitpurpose,代码行数:34,代码来源:model-post.php
示例8: get_recent_pages
public static function get_recent_pages($orders, $pagination, $allow_autodrafts = false)
{
global $wpdb;
if (!array_key_exists('date', $orders)) {
$orders['date'] = 'DESC';
}
$sql_autodrafts = " AND post_status != 'auto-draft' ";
if ($allow_autodrafts) {
$sql_autodrafts = '';
}
$total_items = $wpdb->get_var("SELECT count(*) FROM {$wpdb->posts} WHERE post_type = 'page' {$sql_autodrafts}");
$current_page = !empty($pagination['current_page']) ? $pagination['current_page'] : 1;
$nb_per_page = !empty($pagination['nb_per_page']) ? $pagination['nb_per_page'] : 10;
$total_pages = $nb_per_page > 0 ? ceil($total_items / $nb_per_page) : 0;
if ($current_page > $total_pages) {
$current_page = $total_pages;
}
$offset = $nb_per_page * ($current_page - 1);
$orderby_data = self::get_sql_orderby_data($orders);
$join = $orderby_data['join'];
$order_by = $orderby_data['order_by'];
//Retrieve Recent page, then cache retrieved data:
//Cannot use get_pages() here because we want to filter/order by Templates,
//marked page infos etc... but we're forgiven if we cache the data after, no?
$sql = "SELECT * FROM {$wpdb->posts} AS p \r\n\t\t\t\t\t\t {$join}\r\n\t\t\t\t\t\t WHERE post_type = 'page' \r\n\t\t\t\t\t\t {$sql_autodrafts}\r\n\t\t\t\t\t\t {$order_by} \r\n\t\t\t\t\t\t LIMIT {$offset}, {$nb_per_page}\r\n\t\t\t\t\t\t ";
$pages = $wpdb->get_results($sql);
//Inspired from WP get_pages() :
//Sanitize before caching so it'll only get done once
$num_pages = count($pages);
for ($i = 0; $i < $num_pages; $i++) {
$pages[$i] = sanitize_post($pages[$i], 'raw');
}
// Update cache.
update_post_cache($pages);
return array('pages' => $pages, 'pagination' => compact('current_page', 'nb_per_page', 'total_items', 'total_pages'));
}
开发者ID:erkmen,项目名称:wpstartersetup,代码行数:36,代码来源:tree_data.php
示例9: BuildSitemap
//.........这里部分代码省略.........
trigger_error("MySQL DB Select failed: " . mysql_error(), E_USER_NOTICE);
return;
}
$postRes = mysql_unbuffered_query($sql, $con);
if (!$postRes) {
trigger_error("MySQL unbuffered query failed: " . mysql_error(), E_USER_NOTICE);
return;
}
}
if ($postRes) {
//#type $prioProvider GoogleSitemapGeneratorPrioProviderBase
$prioProvider = NULL;
if ($this->GetOption("b_prio_provider") != '') {
$providerClass = $this->GetOption('b_prio_provider');
$prioProvider = new $providerClass($commentCount, $postCount);
}
//$posts is used by Alex King's Popularity Contest plugin
//if($posts == null || !is_array($posts)) {
// $posts = &$postRes;
//}
$z = 1;
$zz = 1;
//Default priorities
$default_prio_posts = $this->GetOption('pr_posts');
$default_prio_pages = $this->GetOption('pr_pages');
//Change frequencies
$cf_pages = $this->GetOption('cf_pages');
$cf_posts = $this->GetOption('cf_posts');
$minPrio = $this->GetOption('pr_posts_min');
//Cycle through all posts and add them
while ($post = mysql_fetch_object($postRes)) {
//Fill the cache with our DB result. Since it's incomplete (no text-content for example), we will clean it later.
$cache = array(&$post);
update_post_cache($cache);
//Set the current working post for other plugins which depend on "the loop"
$GLOBALS['post'] =& $post;
$permalink = get_permalink($post->ID);
if ($permalink != $home && $post->ID != $homePid) {
$isPage = false;
if ($nxtCompat) {
$isPage = $post->post_status == 'static';
} else {
$isPage = $post->post_type == 'page';
}
//Default Priority if auto calc is disabled
$prio = 0;
if ($isPage) {
//Priority for static pages
$prio = $default_prio_pages;
} else {
//Priority for normal posts
$prio = $default_prio_posts;
}
//If priority calc. is enabled, calculate (but only for posts, not pages)!
if ($prioProvider !== null && !$isPage) {
//Comment count for this post
$cmtcnt = isset($comments[$post->ID]) ? $comments[$post->ID] : 0;
$prio = $prioProvider->GetPostPriority($post->ID, $cmtcnt, $post);
if ($debug) {
$this->AddElement(new GoogleSitemapGeneratorDebugEntry('Debug: Priority report of postID ' . $post->ID . ': Comments: ' . $cmtcnt . ' of ' . $commentCount . ' = ' . $prio . ' points'));
}
}
if (!$isPage && $minPrio > 0 && $prio < $minPrio) {
$prio = $minPrio;
}
//Add it
开发者ID:nxtclass,项目名称:NXTClass-Plugin,代码行数:67,代码来源:sitemap-core.php
示例10: posts
/**
* posts()
*
* @return void
**/
function posts()
{
global $wpdb;
$sql = "\n\t\t\tSELECT\tposts.ID,\n\t\t\t\t\tposts.post_author,\n\t\t\t\t\tposts.post_name,\n\t\t\t\t\tposts.post_type,\n\t\t\t\t\tposts.post_status,\n\t\t\t\t\tposts.post_parent,\n\t\t\t\t\tposts.post_date,\n\t\t\t\t\tposts.post_modified,\n\t\t\t\t\tCAST(posts.post_modified AS DATE) as lastmod,\n\t\t\t\t\tCASE COUNT(DISTINCT CAST(revisions.post_date AS DATE))\n\t\t\t\t\tWHEN 0\n\t\t\t\t\tTHEN\n\t\t\t\t\t\t0\n\t\t\t\t\tELSE\n\t\t\t\t\t\tDATEDIFF(CAST(NOW() AS DATE), CAST(posts.post_date AS DATE))\n\t\t\t\t\t\t/ COUNT(DISTINCT CAST(revisions.post_date AS DATE))\n\t\t\t\t\tEND as changefreq\n\t\t\tFROM\t{$wpdb->posts} as posts\n\t\t\tLEFT JOIN {$wpdb->posts} as revisions\n\t\t\tON\t\trevisions.post_parent = posts.ID\n\t\t\tAND\t\trevisions.post_type = 'revision'\n\t\t\tAND\t\tDATEDIFF(CAST(revisions.post_date AS DATE), CAST(posts.post_date AS DATE)) > 2\n\t\t\tAND\t\tDATE_SUB(CAST(NOW() AS DATE), INTERVAL 1 YEAR) < CAST(revisions.post_date AS DATE)\n\t\t\tLEFT JOIN {$wpdb->postmeta} as redirect_url\n\t\t\tON\t\tredirect_url.post_id = posts.ID\n\t\t\tAND\t\tredirect_url.meta_key = '_redirect_url'\n\t\t\tLEFT JOIN {$wpdb->postmeta} as widgets_exclude\n\t\t\tON\t\twidgets_exclude.post_id = posts.ID\n\t\t\tAND\t\twidgets_exclude.meta_key = '_widgets_exclude'\n\t\t\tLEFT JOIN {$wpdb->postmeta} as widgets_exception\n\t\t\tON\t\twidgets_exception.post_id = posts.ID\n\t\t\tAND\t\twidgets_exception.meta_key = '_widgets_exception'\n\t\t\tWHERE\tposts.post_type = 'post'\n\t\t\tAND\t\tposts.post_status = 'publish'\n\t\t\tAND\t\tposts.post_password = ''\n\t\t\tAND\t\tredirect_url.post_id IS NULL\n\t\t\tAND\t\t( widgets_exclude.post_id IS NULL OR widgets_exception.post_id IS NOT NULL )\n\t\t\tGROUP BY posts.ID\n\t\t\tORDER BY posts.post_parent, posts.ID\n\t\t\t";
#dump($sql);
$posts = $wpdb->get_results($sql);
update_post_cache($posts);
foreach ($posts as $post) {
$this->write(apply_filters('the_permalink', get_permalink($post->ID)), $post->lastmod, $post->changefreq, 0.6);
}
}
开发者ID:hurtzi,项目名称:Marino-Pardo-WEB-,代码行数:16,代码来源:xml-sitemaps-utils.php
示例11: redo_search
function redo_search($the_posts = array())
{
global $wpdb;
global $wp_query;
if (is_search()) {
$GLOBALS['sem_s'] = get_query_var('s');
preg_match_all("/((\\w|-)+)/", $GLOBALS['sem_s'], $out);
$keywords = current($out);
if (empty($keywords)) {
return array();
}
$query_string = "";
$keyword_filter = "";
foreach ($keywords as $keyword) {
$query_string .= ($query_string ? " " : "") . $keyword;
$reg_one_present .= ($reg_one_present ? "|" : "") . $keyword;
}
$paged = $wp_query->get('paged');
if (!$paged) {
$paged = 1;
}
$posts_per_page = $wp_query->get('posts_per_page');
if (!$posts_per_page) {
$posts_per_page = get_settings('posts_per_page');
}
$offset = ($paged - 1) * $posts_per_page;
$now = gmdate('Y-m-d H:i:00', strtotime("+1 minute"));
if (isset($GLOBALS['sem_static_front'])) {
$GLOBALS['sem_static_front']->init();
}
if (isset($GLOBALS['sem_sidebar_tile'])) {
$GLOBALS['sem_sidebar_tile']->init();
}
$search_query = "\r\n\t\t\t\tSELECT\r\n\t\t\t\t\tDISTINCT posts.*,\r\n\t\t\t\t\tCASE\r\n\t\t\t\t\t\tWHEN posts.post_title REGEXP '{$reg_one_present}'\r\n\t\t\t\t\t\t\tTHEN 1\r\n\t\t\t\t\t\t\tELSE 0\r\n\t\t\t\t\t\tEND AS keyword_in_title,\r\n\t\t\t\t\tMATCH ( posts.post_title, posts.post_content )\r\n\t\t\t\t\t\tAGAINST ( '" . addslashes($query_string) . "' ) AS mysql_score\r\n\t\t\t\tFROM\r\n\t\t\t\t\t{$wpdb->posts} as posts\r\n\t\t\t\tLEFT JOIN {$wpdb->postmeta} as postmeta\r\n\t\t\t\t\tON postmeta.post_id = posts.ID\r\n\t\t\t\tWHERE\r\n\t\t\t\t\tposts.post_date_gmt <= '" . $now . "'" . (defined('sem_home_page_id') && sem_home_page_id ? "\r\n\t\t\t\t\tAND posts.ID <> " . intval(sem_home_page_id) : "") . (defined('sem_sidebar_tile_id') && sem_sidebar_tile_id ? "\r\n\t\t\t\t\tAND posts.ID <> " . intval(sem_sidebar_tile_id) : "") . "\r\n\t\t\t\t\tAND ( posts.post_password = '' )\r\n\t\t\t\t\tAND ( " . (function_exists('get_site_option') ? "( post_status = 'publish' AND ( post_type = 'post' OR ( post_type = 'page' AND postmeta.meta_value = 'article.php' ) ) )" : "( post_status = 'publish' OR ( post_status = 'static' AND postmeta.meta_value = 'article.php' ) )") . " )\r\n\t\t\t\t\tAND ( posts.post_title REGEXP '{$reg_one_present}' OR posts.post_content REGEXP '{$reg_one_present}' )\r\n\t\t\t\tGROUP BY\r\n\t\t\t\t\tposts.ID\r\n\t\t\t\tORDER BY\r\n\t\t\t\t\tkeyword_in_title DESC, mysql_score DESC, posts.post_date DESC\r\n\t\t\t\tLIMIT " . intval($offset) . ", " . intval($posts_per_page);
$request_query = "\r\n\t\t\t\tSELECT\r\n\t\t\t\t\tDISTINCT posts.*\r\n\t\t\t\tFROM\r\n\t\t\t\t\t{$wpdb->posts} as posts\r\n\t\t\t\tLEFT JOIN {$wpdb->postmeta} as postmeta\r\n\t\t\t\t\tON postmeta.post_id = posts.ID\r\n\t\t\t\tWHERE\r\n\t\t\t\t\tposts.post_date_gmt <= '" . $now . "'" . (defined('sem_home_page_id') && sem_home_page_id ? "\r\n\t\t\t\t\tAND posts.ID <> " . intval(sem_home_page_id) : "") . (defined('sem_sidebar_tile_id') && sem_sidebar_tile_id ? "\r\n\t\t\t\t\tAND posts.ID <> " . intval(sem_sidebar_tile_id) : "") . "\r\n\t\t\t\t\tAND ( posts.post_password = '' )\r\n\t\t\t\t\tAND ( " . (function_exists('get_site_option') ? "( post_status = 'publish' AND ( post_type = 'post' OR ( post_type = 'page' AND postmeta.meta_value = 'article.php' ) ) )" : "( post_status = 'publish' OR ( post_status = 'static' AND postmeta.meta_value = 'article.php' ) )") . " )\r\n\t\t\t\t\tAND ( posts.post_title REGEXP '{$reg_one_present}' OR posts.post_content REGEXP '{$reg_one_present}' )\r\n\t\t\t\tGROUP BY\r\n\t\t\t\t\tposts.ID\r\n\t\t\t\tLIMIT " . intval($offset) . ", " . intval($posts_per_page);
$the_posts = $wpdb->get_results($search_query);
$GLOBALS['request'] = ' ' . preg_replace("/[\n\r\\s]+/", " ", $request_query) . ' ';
if (function_exists('update_post_cache')) {
update_post_cache($the_posts);
}
if (function_exists('update_page_cache')) {
update_page_cache($the_posts);
}
}
return $the_posts;
}
开发者ID:jbogota,项目名称:blog-king,代码行数:46,代码来源:sem-search-reloaded.php
示例12: get_posts
/**
* get_posts()
*
* @param string $query
* @return array $results
**/
function get_posts($query)
{
global $wp_query;
$results = false;
if ($wp_query->is_preview || $wp_query->is_robots || isset($_GET['trashed'])) {
# bail: we don't want to cache this stuff
return $results;
}
if ($wp_query->is_singular) {
$post_id = wp_cache_get(self::$cache_id, 'url2post_id');
if ($post_id === 0) {
$results = array();
$this->cache_hits++;
} elseif ($post_id) {
$post = wp_cache_get($post_id, 'posts');
if ($post !== false) {
$results = array($post);
$this->cache_hits++;
}
}
if ($results !== false) {
return $results;
}
if (isset($_GET['action']) || isset($_GET['doing_wp_cron']) || isset($_GET['debug']) || isset($_GET['preview']) || defined('WP_INSTALLING') && WP_INSTALLING || defined('WP_ADMIN') && WP_ADMIN || defined('DOING_CRON') && DOING_CRON || defined('DOING_AJAX') && DOING_AJAX || $_POST) {
return $results;
}
$results = self::$wpdb->get_results($query);
if ($results) {
update_post_cache($results);
$post_id = $results[0]->ID;
} else {
$post_id = 0;
}
if (!$post_id || $wp_query->is_feed) {
$timeout = min(3600, cache_timeout);
} elseif ($wp_query->is_paged || self::$cache_id != md5(get_permalink($post_id))) {
$timeout = cache_timeout;
} else {
$timeout = 0;
}
wp_cache_add(self::$cache_id, $post_id, 'url2post_id', $timeout);
} else {
if (!$wp_query->is_singular && is_user_logged_in()) {
$query = self::maybe_strip_private_posts($query);
}
if (strpos($query, "'private'") !== false) {
# bail: queries that return private posts can't be efficiently cached
return $results;
}
$posts = wp_cache_get(self::$cache_id, 'url2posts');
$found = wp_cache_get(self::$cache_id, 'url2posts_found');
if ($posts !== false && $found !== false) {
$results = $posts;
self::$found = $found;
$this->cache_hits++;
return $results;
}
if (isset($_GET['action']) || isset($_GET['doing_wp_cron']) || isset($_GET['debug']) || isset($_GET['preview']) || defined('WP_INSTALLING') && WP_INSTALLING || defined('WP_ADMIN') && WP_ADMIN || defined('DOING_CRON') && DOING_CRON || defined('DOING_AJAX') && DOING_AJAX || $_POST) {
return $results;
}
if ($wp_query->is_home || $wp_query->is_category || $wp_query->is_tag || $wp_query->is_author || $wp_query->is_date || $wp_query->is_feed && !$wp_query->is_singular && !$wp_query->is_archive) {
$results = self::$wpdb->get_results($query);
self::$found = self::$wpdb->get_var("SELECT FOUND_ROWS()");
if (!$results || $wp_query->is_feed || redirect_canonical(null, false)) {
$timeout = min(3600, cache_timeout);
} elseif ($wp_query->is_paged) {
$timeout = cache_timeout;
} else {
$timeout = 0;
}
wp_cache_add(self::$cache_id, $results, 'url2posts', $timeout);
wp_cache_add(self::$cache_id, self::$found, 'url2posts_found', $timeout);
}
}
return $results;
}
开发者ID:semiologic,项目名称:sem-cache,代码行数:82,代码来源:query-cache.php
示例13: flt_get_pages
//.........这里部分代码省略.........
// will still be teased. This is a slight design compromise to satisfy potentially conflicting user goals without yet another option
$pages = apply_filters('objects_results_rs', $pages, 'post', (array) $post_type, array('request' => $query, 'force_teaser' => true, 'object_type' => $post_type));
// restore buffered titles in case they were filtered previously
scoper_restore_property_array($pages, $titles, 'ID', 'post_title');
$pages = apply_filters('objects_teaser_rs', $pages, 'post', $post_type, array('request' => $query, 'force_teaser' => true));
if ($frontend_list_private) {
if (!scoper_get_otype_option('teaser_hide_private', 'post', $post_type)) {
$tease_all = true;
}
}
} else {
$_args = array('skip_teaser' => true, 'retain_status' => $force_publish_status);
if (in_array($GLOBALS['pagenow'], array('post.php', 'post-new.php'))) {
if ($post_type_obj = get_post_type_object($post_type)) {
$plural_name = plural_name_from_cap_rs($post_type_obj);
$_args['alternate_reqd_caps'][0] = array("create_child_{$plural_name}");
}
}
// Pass query through the request filter
$query = apply_filters('objects_request_rs', $query, 'post', $post_type, $_args);
// Execute the filtered query
$pages = scoper_get_results($query);
// restore buffered titles in case they were filtered previously
scoper_restore_property_array($pages, $titles, 'ID', 'post_title');
}
if (empty($pages)) {
// alternate hook name (WP core already applied get_pages filter)
return apply_filters('get_pages_rs', array(), $r);
}
//
// === END Role Scoper MODIFICATION ===
// ====================================
// Role Scoper note: WP core get_pages has already updated wp_cache and pagecache with unfiltered results.
update_post_cache($pages);
// === BEGIN Role Scoper MODIFICATION: Support a disjointed pages tree with some parents hidden ========
if ($child_of || empty($tease_all)) {
// if we're including all pages with teaser, no need to continue thru tree remapping
$ancestors = ScoperAncestry::get_page_ancestors();
// array of all ancestor IDs for keyed page_id, with direct parent first
$orderby = $sort_column;
if ($parent > 0 || !$hierarchical) {
$remap_parents = false;
} else {
// if these settings were passed into this get_pages call, use them
if (-1 === $remap_parents) {
$remap_parents = scoper_get_option('remap_page_parents');
}
if ($remap_parents) {
if (-1 === $enforce_actual_depth) {
$enforce_actual_depth = scoper_get_option('enforce_actual_page_depth');
}
if (-1 === $remap_thru_excluded_parent) {
$remap_thru_excluded_parent = scoper_get_option('remap_thru_excluded_page_parent');
}
}
}
$remap_args = compact('child_of', 'parent', 'exclude', 'depth', 'orderby', 'remap_parents', 'enforce_actual_depth', 'remap_thru_excluded_parent');
// one or more of these args may have been modified after extraction
ScoperHardway::remap_tree($pages, $ancestors, 'ID', 'post_parent', $remap_args);
}
// === END Role Scoper MODIFICATION ===
// ====================================
if (!empty($exclude_tree)) {
$exclude = array();
$exclude = (int) $exclude_tree;
$children = get_page_children($exclude, $pages);
开发者ID:joostrijneveld,项目名称:cscircles-wp-content,代码行数:67,代码来源:hardway_rs.php
示例14: get_pages
//.........这里部分代码省略.........
$post_parent__in = implode(',', array_map('absint', (array) $parent));
if (!empty($post_parent__in)) {
$where .= " AND post_parent IN ({$post_parent__in})";
}
} elseif ($parent >= 0) {
$where .= $hqdb->prepare(' AND post_parent = %d ', $parent);
}
if (1 == count($post_status)) {
$where_post_type = $hqdb->prepare("post_type = %s AND post_status = %s", $r['post_type'], reset($post_status));
} else {
$post_status = implode("', '", $post_status);
$where_post_type = $hqdb->prepare("post_type = %s AND post_status IN ('{$post_status}')", $r['post_type']);
}
$orderby_array = array();
$allowed_keys = array('author', 'post_author', 'date', 'post_date', 'title', 'post_title', 'name', 'post_name', 'modified', 'post_modified', 'modified_gmt', 'post_modified_gmt', 'menu_order', 'parent', 'post_parent', 'ID', 'rand', 'comment_count');
foreach (explode(',', $r['sort_column']) as $orderby) {
$orderby = trim($orderby);
if (!in_array($orderby, $allowed_keys)) {
continue;
}
switch ($orderby) {
case 'menu_order':
break;
case 'ID':
$orderby = "{$hqdb->posts}.ID";
break;
case 'rand':
$orderby = 'RAND()';
break;
case 'comment_count':
$orderby = "{$hqdb->posts}.comment_count";
break;
default:
if (0 === strpos($orderby, 'post_')) {
$orderby = "{$hqdb->posts}." . $orderby;
} else {
$orderby = "{$hqdb->posts}.post_" . $orderby;
}
}
$orderby_array[] = $orderby;
}
$sort_column = !empty($orderby_array) ? implode(',', $orderby_array) : "{$hqdb->posts}.post_title";
$sort_order = strtoupper($r['sort_order']);
if ('' !== $sort_order && !in_array($sort_order, array('ASC', 'DESC'))) {
$sort_order = 'ASC';
}
$query = "SELECT * FROM {$hqdb->posts} {$join} WHERE ({$where_post_type}) {$where} ";
$query .= $author_query;
$query .= " ORDER BY " . $sort_column . " " . $sort_order;
if (!empty($number)) {
$query .= ' LIMIT ' . $offset . ',' . $number;
}
$pages = $hqdb->get_results($query);
if (empty($pages)) {
/** This filter is documented in hq-includes/post.php */
$pages = apply_filters('get_pages', array(), $r);
return $pages;
}
// Sanitize before caching so it'll only get done once.
$num_pages = count($pages);
for ($i = 0; $i < $num_pages; $i++) {
$pages[$i] = sanitize_post($pages[$i], 'raw');
}
// Update cache.
update_post_cache($pages);
if ($child_of || $hierarchical) {
$pages = get_page_children($child_of, $pages);
}
if (!empty($r['exclude_tree'])) {
$exclude = hq_parse_id_list($r['exclude_tree']);
foreach ($exclude as $id) {
$children = get_page_children($id, $pages);
foreach ($children as $child) {
$exclude[] = $child->ID;
}
}
$num_pages = count($pages);
for ($i = 0; $i < $num_pages; $i++) {
if (in_array($pages[$i]->ID, $exclude)) {
unset($pages[$i]);
}
}
}
$page_structure = array();
foreach ($pages as $page) {
$page_structure[] = $page->ID;
}
hq_cache_set($cache_key, $page_structure, 'posts');
// Convert to HQ_Post instances
$pages = array_map('get_post', $pages);
/**
* Filter the retrieved list of pages.
*
* @since 0.0.1
*
* @param array $pages List of pages to retrieve.
* @param array $r Array of get_pages() arguments.
*/
return apply_filters('get_pages', $pages, $r);
}
开发者ID:gcorral,项目名称:hivequeen,代码行数:101,代码来源:post.php
示例15: BuildSitemap
//.........这里部分代码省略.........
trigger_error("MySQL DB Select failed: " . mysql_error(), E_USER_NOTICE);
return;
}
$postRes = mysql_unbuffered_query($sql, $con);
if (!$postRes) {
trigger_error("MySQL unbuffered query failed: " . mysql_error(), E_USER_NOTICE);
return;
}
}
if ($postRes) {
//#type $prioProvider GoogleSitemapGeneratorPrioProviderBase
$prioProvider = NULL;
if ($this->GetOption("b_prio_provider") != '') {
$providerClass = $this->GetOption('b_prio_provider');
$prioProvider = new $providerClass($commentCount, $postCount);
}
//$posts is used by Alex King's Popularity Contest plugin
//if($posts == null || !is_array($posts)) {
// $posts = &$postRes;
//}
$z = 1;
$zz = 1;
//Default priorities
$default_prio_posts = $this->GetOption('pr_posts');
$default_prio_pages = $this->GetOption('pr_pages');
//Change frequencies
$cf_pages = $this->GetOption('sm_cf_pages');
$cf_posts = $this->GetOption('sm_cf_posts');
$minPrio = $this->GetOption('pr_posts_min');
//Cycle through all posts and add them
while ($post = mysql_fetch_object($postRes)) {
//Fill the cache with our DB result. Since it's incomplete (no text-content for example), we will clean it later.
$cache = array(&$post);
update_post_cache($cache);
$permalink = get_permalink($post->ID);
if ($permalink != $home) {
$isPage = false;
if ($wpCompat) {
$isPage = $post->post_status == 'static';
} else {
$isPage = $post->post_type == 'page';
}
//Set the current working post
$GLOBALS['post'] =& $post;
//Default Priority if auto calc is disabled
$prio = 0;
if ($isPage) {
//Priority for static pages
$prio = $default_prio_pages;
} else {
//Priority for normal posts
$prio = $default_prio_posts;
}
//If priority calc. is enabled, calculate (but only for posts, not pages)!
if ($prioProvider !== null && !$isPage) {
//Comment count for this post
$cmtcnt = isset($comments[$post->ID]) ? $comments[$post->ID] : 0;
$prio = $prioProvider->GetPostPriority($post->ID, $cmtcnt);
if ($debug) {
$this->AddElement(new GoogleSitemapGeneratorDebugEntry('Debug: Priority report of postID ' . $post->ID . ': Comments: ' . $cmtcnt . ' of ' . $commentCount . ' = ' . $prio . ' points'));
}
}
if (!$isPage && $minPrio > 0 && $prio < $minPrio) {
$prio = $minPrio;
}
//Add it
开发者ID:prabhu,项目名称:desistartups,代码行数:67,代码来源:sitemap.php
示例16: flt_get_pages
//.........这里部分代码省略.........
// execute unfiltered query
// Pass results of unfiltered query through the teaser filter.
// If listing private pages is disabled, they will be omitted completely, but restricted published pages
// will still be teased. This is a slight design compromise to satisfy potentially conflicting user goals without yet another option
$pages = apply_filters('pp_posts_teaser', $pages, $post_type, array('request' => $query, 'force_teaser' => true));
$tease_all = true;
} else {
$_args = array('skip_teaser' => true, 'retain_status' => $force_publish_status);
$groupby = $distinct = '';
global $pagenow;
if (in_array($pagenow, array('post.php', 'post-new.php'))) {
$clauses = apply_filters('pp_get_pages_clauses', compact('distinct', 'fields', 'join', 'where', 'groupby', 'orderby', 'limits'), $post_type, $args);
} else {
// Pass query through the request filter
$_args['post_types'] = $post_type;
if ($required_operation) {
$_args['required_operation'] = $required_operation;
} else {
$_args['required_operation'] = pp_is_front() && !is_preview() ? 'read' : 'edit';
}
if ('edit' == $_args['required_operation'] && isset($args['post_parent']) || 'associate' == $alternate_operation) {
// workaround for CMS Page View
$_args['alternate_required_ops'] = array('associate');
}
$clauses = apply_filters('pp_posts_clauses', compact('distinct', 'fields', 'join', 'where', 'groupby', 'orderby', 'limits'), $_args);
}
// Execute the filtered query
$pages = $wpdb->get_results("SEL
|
请发表评论