本文整理汇总了PHP中update_post_caches函数的典型用法代码示例。如果您正苦于以下问题:PHP update_post_caches函数的具体用法?PHP update_post_caches怎么用?PHP update_post_caches使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了update_post_caches函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: widget
/**
* Display the widget
*/
function widget($args, $instance)
{
global $wp_query, $post;
extract($args);
echo $before_widget;
// Title
$title = apply_filters('widget_title', $instance['title']);
if (!empty($title)) {
echo $before_title . $title . $after_title;
}
// Number of posts
if (!($number = (int) $instance['number'])) {
$number = 5;
} else {
if ($number < 1) {
$number = 1;
} else {
if ($number > 15) {
$number = 15;
}
}
}
// Create Query
$posts_query = array('post__in' => get_option('sticky_posts'), 'posts_per_page' => $number, 'orderby' => 'date', 'post_status' => 'publish');
$sticky_posts = new WP_Query($posts_query);
// The Loop
echo '<ul>';
while ($sticky_posts->have_posts()) {
$sticky_posts->the_post();
update_post_caches($posts);
echo '<li>';
if (locate_template(array('themeable-sticky-post.php', 'themeable-sticky-post-widget.php'))) {
get_template_part('themeable-sticky-post', 'widget');
} else {
$plugin_templates_path = WP_PLUGIN_DIR . '/' . str_replace(basename(__FILE__), '', plugin_basename(__FILE__)) . 'templates/';
include $plugin_templates_path . 'list.php';
}
echo '</li>';
}
$post = $wp_query->post;
setup_postdata($post);
echo '</ul>';
echo $after_widget;
}
开发者ID:blocher,项目名称:oneholyname,代码行数:47,代码来源:themeable-sticky-posts.php
示例2: get_posts
//.........这里部分代码省略.........
$this->posts = apply_filters_ref_array('es_posts_results', array($this->posts, &$this));
}
// @todo: address this
if (0 && !empty($this->posts) && $this->is_comment_feed && $this->is_singular) {
$cjoin = apply_filters_ref_array('es_comment_feed_join', array('', &$this));
$cwhere = apply_filters_ref_array('es_comment_feed_where', array("WHERE comment_post_ID = '{$this->posts[0]->ID}' AND comment_approved = '1'", &$this));
$cgroupby = apply_filters_ref_array('es_comment_feed_groupby', array('', &$this));
$cgroupby = !empty($cgroupby) ? 'GROUP BY ' . $cgroupby : '';
$corderby = apply_filters_ref_array('es_comment_feed_orderby', array('comment_date_gmt DESC', &$this));
$corderby = !empty($corderby) ? 'ORDER BY ' . $corderby : '';
$climits = apply_filters_ref_array('es_comment_feed_limits', array('LIMIT ' . get_option('posts_per_rss'), &$this));
$comments_request = "SELECT {$wpdb->comments}.* FROM {$wpdb->comments} {$cjoin} {$cwhere} {$cgroupby} {$corderby} {$climits}";
$this->comments = $wpdb->get_results($comments_request);
$this->comment_count = count($this->comments);
}
// Check post status to determine if post should be displayed.
if (!empty($this->posts) && ($this->is_single || $this->is_page)) {
$status = get_post_status($this->posts[0]);
$post_status_obj = get_post_status_object($status);
//$type = get_post_type($this->posts[0]);
if (!$post_status_obj->public) {
if (!is_user_logged_in()) {
// User must be logged in to view unpublished posts.
$this->posts = array();
} else {
if ($post_status_obj->protected) {
// User must have edit permissions on the draft to preview.
if (!current_user_can($edit_cap, $this->posts[0]->ID)) {
$this->posts = array();
} else {
$this->is_preview = true;
if ('future' != $status) {
$this->posts[0]->post_date = current_time('mysql');
}
}
} elseif ($post_status_obj->private) {
if (!current_user_can($read_cap, $this->posts[0]->ID)) {
$this->posts = array();
}
} else {
$this->posts = array();
}
}
}
if ($this->is_preview && $this->posts && current_user_can($edit_cap, $this->posts[0]->ID)) {
$this->posts[0] = get_post(apply_filters_ref_array('es_the_preview', array($this->posts[0], &$this)));
}
}
// @todo: address this
// Put sticky posts at the top of the posts array
$sticky_posts = get_option('sticky_posts');
if (0 && $this->is_home && $page <= 1 && is_array($sticky_posts) && !empty($sticky_posts) && !$q['ignore_sticky_posts']) {
$num_posts = count($this->posts);
$sticky_offset = 0;
// Loop over posts and relocate stickies to the front.
for ($i = 0; $i < $num_posts; $i++) {
if (in_array($this->posts[$i]->ID, $sticky_posts)) {
$sticky_post = $this->posts[$i];
// Remove sticky from current position
array_splice($this->posts, $i, 1);
// Move to front, after other stickies
array_splice($this->posts, $sticky_offset, 0, array($sticky_post));
// Increment the sticky offset. The next sticky will be placed at this offset.
$sticky_offset++;
// Remove post from sticky posts array
$offset = array_search($sticky_post->ID, $sticky_posts);
unset($sticky_posts[$offset]);
}
}
// If any posts have been excluded specifically, Ignore those that are sticky.
if (!empty($sticky_posts) && !empty($q['post__not_in'])) {
$sticky_posts = array_diff($sticky_posts, $q['post__not_in']);
}
// Fetch sticky posts that weren't in the query results
if (!empty($sticky_posts)) {
$stickies = get_posts(array('post__in' => $sticky_posts, 'post_type' => $post_type, 'post_status' => 'publish', 'nopaging' => true));
foreach ($stickies as $sticky_post) {
array_splice($this->posts, $sticky_offset, 0, array($sticky_post));
$sticky_offset++;
}
}
}
if (!$q['suppress_filters']) {
$this->posts = apply_filters_ref_array('es_the_posts', array($this->posts, &$this));
}
// Ensure that any posts added/modified via one of the filters above are
// of the type WP_Post and are filtered.
if ($this->posts) {
$this->post_count = count($this->posts);
$this->posts = array_map('get_post', $this->posts);
if ($q['cache_results']) {
update_post_caches($this->posts, $post_type, $q['update_post_term_cache'], $q['update_post_meta_cache']);
}
$this->post = reset($this->posts);
} else {
$this->post_count = 0;
$this->posts = array();
}
return $this->posts;
}
开发者ID:GiantRobX,项目名称:wordpress-vip-plugins,代码行数:101,代码来源:class-es-wp-query-wrapper.php
示例3: displaySubtleAds
</div>
</div>
<?php
if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Advert_3')) {
if (function_exists(displaySubtleAds)) {
displaySubtleAds(3);
}
}
?>
<br class="clear" />
<?php
$post = $temp_post;
update_post_caches($post_id);
comments_template();
?>
<?php
}
} else {
?>
<p><?php
_e("Sorry, no posts matched your criteria.", 'gluedideas_subtle');
?>
</p>
<?php
}
开发者ID:rmccue,项目名称:wordpress-unit-tests,代码行数:31,代码来源:single.php
示例4: _prime_post_caches
/**
* Adds any posts from the given ids to the cache that do not already exist in cache
*
* @since 3.4.0
* @access private
*
* @see update_post_caches()
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param array $ids ID list.
* @param bool $update_term_cache Optional. Whether to update the term cache. Default true.
* @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true.
*/
function _prime_post_caches($ids, $update_term_cache = true, $update_meta_cache = true)
{
global $wpdb;
$non_cached_ids = _get_non_cached_ids($ids, 'posts');
if (!empty($non_cached_ids)) {
$fresh_posts = $wpdb->get_results(sprintf("SELECT {$wpdb->posts}.* FROM {$wpdb->posts} WHERE ID IN (%s)", join(",", $non_cached_ids)));
update_post_caches($fresh_posts, 'any', $update_term_cache, $update_meta_cache);
}
}
开发者ID:SayenkoDesign,项目名称:ividf,代码行数:23,代码来源:post.php
示例5: do_action_ref_array
//.........这里部分代码省略.........
$this->comments = $wpdb->get_results($comments_request);
$this->comment_count = count($this->comments);
}
// Check post status to determine if post should be displayed.
if (!empty($this->posts) && ($this->is_single || $this->is_page)) {
$status = get_post_status($this->posts[0]->ID);
$post_status_obj = get_post_status_object($status);
//$type = get_post_type($this->posts[0]);
if (!$post_status_obj->public) {
if (!is_user_logged_in()) {
// User must be logged in to view unpublished posts.
$this->posts = array();
} else {
if ($post_status_obj->protected) {
// User must have edit permissions on the draft to preview.
if (!current_user_can($edit_cap, $this->posts[0]->ID)) {
$this->posts = array();
} else {
$this->is_preview = true;
if ('future' != $status) {
$this->posts[0]->post_date = current_time('mysql');
}
}
} elseif ($post_status_obj->private) {
if (!current_user_can($read_cap, $this->posts[0]->ID)) {
$this->posts = array();
}
} else {
$this->posts = array();
}
}
}
if ($this->is_preview && $this->posts && current_user_can($edit_cap, $this->posts[0]->ID)) {
$this->posts[0] = apply_filters_ref_array('the_preview', array($this->posts[0], &$this));
}
}
// Put sticky posts at the top of the posts array
$sticky_posts = get_option('sticky_posts');
if ($this->is_home && $page <= 1 && is_array($sticky_posts) && !empty($sticky_posts) && !$q['ignore_sticky_posts']) {
$num_posts = count($this->posts);
$sticky_offset = 0;
// Loop over posts and relocate stickies to the front.
for ($i = 0; $i < $num_posts; $i++) {
if (in_array($this->posts[$i]->ID, $sticky_posts)) {
$sticky_post = $this->posts[$i];
// Remove sticky from current position
array_splice($this->posts, $i, 1);
// Move to front, after other stickies
array_splice($this->posts, $sticky_offset, 0, array($sticky_post));
// Increment the sticky offset. The next sticky will be placed at this offset.
$sticky_offset++;
// Remove post from sticky posts array
$offset = array_search($sticky_post->ID, $sticky_posts);
unset($sticky_posts[$offset]);
}
}
// If any posts have been excluded specifically, Ignore those that are sticky.
if (!empty($sticky_posts) && !empty($q['post__not_in'])) {
$sticky_posts = array_diff($sticky_posts, $q['post__not_in']);
}
// Fetch sticky posts that weren't in the query results
if (!empty($sticky_posts)) {
$stickies__in = implode(',', array_map('absint', $sticky_posts));
// honor post type(s) if not set to any
$stickies_where = '';
if ('any' != $post_type && '' != $post_type) {
if (is_array($post_type)) {
$post_types = join("', '", $post_type);
} else {
$post_types = $post_type;
}
$stickies_where = "AND {$wpdb->posts}.post_type IN ('" . $post_types . "')";
}
$stickies = $wpdb->get_results("SELECT * FROM {$wpdb->posts} WHERE {$wpdb->posts}.ID IN ({$stickies__in}) {$stickies_where}");
foreach ($stickies as $sticky_post) {
// Ignore sticky posts the current user cannot read or are not published.
if ('publish' != $sticky_post->post_status) {
continue;
}
array_splice($this->posts, $sticky_offset, 0, array($sticky_post));
$sticky_offset++;
}
}
}
if (!$q['suppress_filters']) {
$this->posts = apply_filters_ref_array('the_posts', array($this->posts, &$this));
}
$this->post_count = count($this->posts);
// Always sanitize
foreach ($this->posts as $i => $post) {
$this->posts[$i] = sanitize_post($post, 'raw');
}
if ($q['cache_results']) {
update_post_caches($this->posts, $post_type, $q['update_post_term_cache'], $q['update_post_meta_cache']);
}
if ($this->post_count > 0) {
$this->post = $this->posts[0];
}
return $this->posts;
}
开发者ID:nunomorgadinho,项目名称:WordPress,代码行数:101,代码来源:query.php
示例6: get_posts
/**
* get_posts() - Returns a number of posts
*
* {@internal Missing Long Description}}
*
* @package WordPress
* @subpackage Post
* @since 1.2
* @uses $wpdb
*
* @param array $args {@internal Missing Description}}
* @return array {@internal Missing Description}}
*/
function get_posts($args = null)
{
global $wpdb;
$defaults = array('numberposts' => 5, 'offset' => 0, 'category' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => 'post', 'post_status' => 'publish', 'post_parent' => 0);
$r = wp_parse_args($args, $defaults);
extract($r, EXTR_SKIP);
$numberposts = (int) $numberposts;
$offset = (int) $offset;
$category = (int) $category;
$post_parent = (int) $post_parent;
$inclusions = '';
if (!empty($include)) {
$offset = 0;
//ignore offset, category, exclude, meta_key, and meta_value, post_parent if using include
$category = 0;
$exclude = '';
$meta_key = '';
$meta_value = '';
$post_parent = 0;
$incposts = preg_split('/[\\s,]+/', $include);
$numberposts = count($incposts);
// only the number of posts included
if (count($incposts)) {
foreach ($incposts as $incpost) {
if (empty($inclusions)) {
$inclusions = $wpdb->prepare(' AND ( ID = %d ', $incpost);
} else {
$inclusions .= $wpdb->prepare(' OR ID = %d ', $incpost);
}
}
}
}
if (!empty($inclusions)) {
$inclusions .= ')';
}
$exclusions = '';
if (!empty($exclude)) {
$exposts = preg_split('/[\\s,]+/', $exclude);
if (count($exposts)) {
foreach ($exposts as $expost) {
if (empty($exclusions)) {
$exclusions = $wpdb->prepare(' AND ( ID <> %d ', $expost);
} else {
$exclusions .= $wpdb->prepare(' AND ID <> %d ', $expost);
}
}
}
}
if (!empty($exclusions)) {
$exclusions .= ')';
}
// orderby
if (preg_match('/.+ +(ASC|DESC)/i', $orderby)) {
$order = '';
}
// orderby has its own order, so we'll use that
$query = "SELECT DISTINCT * FROM {$wpdb->posts} ";
$query .= empty($category) ? '' : ", {$wpdb->term_relationships}, {$wpdb->term_taxonomy} ";
$query .= empty($meta_key) ? '' : ", {$wpdb->postmeta} ";
$query .= " WHERE 1=1 ";
$query .= empty($post_type) ? '' : $wpdb->prepare("AND post_type = %s ", $post_type);
$query .= empty($post_status) ? '' : $wpdb->prepare("AND post_status = %s ", $post_status);
$query .= "{$exclusions} {$inclusions} ";
$query .= empty($category) ? '' : $wpdb->prepare("AND ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id AND {$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id AND {$wpdb->term_taxonomy}.term_id = %d AND {$wpdb->term_taxonomy}.taxonomy = 'category')", $category);
$query .= empty($post_parent) ? '' : $wpdb->prepare("AND {$wpdb->posts}.post_parent = %d ", $post_parent);
// expected_slashed ($meta_key, $meta_value) -- Also, this looks really funky, doesn't seem like it works
$query .= empty($meta_key) | empty($meta_value) ? '' : " AND ({$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '{$meta_key}' AND {$wpdb->postmeta}.meta_value = '{$meta_value}' )";
$query .= empty($post_mime_type) ? '' : wp_post_mime_type_where($post_mime_type);
$query .= " GROUP BY {$wpdb->posts}.ID ORDER BY " . $orderby . ' ' . $order;
if (0 < $numberposts) {
$query .= $wpdb->prepare(" LIMIT %d,%d", $offset, $numberposts);
}
$posts = $wpdb->get_results($query);
update_post_caches($posts);
return $posts;
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:89,代码来源:post.php
示例7: array
//.........这里部分代码省略.........
$where .= " OR post_author = $user_ID AND post_status != 'draft' AND post_status != 'static')";
else
$where .= ')';
}
if (! $this->is_attachment )
$where .= " AND post_status != 'attachment'";
// Apply filters on where and join prior to paging so that any
// manipulations to them are reflected in the paging by day queries.
$where = apply_filters('posts_where', $where);
$join = apply_filters('posts_join', $join);
// Paging
if (empty($q['nopaging']) && ! $this->is_single && ! $this->is_page) {
$page = abs(intval($q['paged']));
if (empty($page)) {
$page = 1;
}
if (($q['what_to_show'] == 'posts')) {
$q['offset'] = abs(intval($q['offset']));
if ( empty($q['offset']) ) {
$pgstrt = '';
$pgstrt = (intval($page) -1) * $q['posts_per_page'] . ', ';
$limits = 'LIMIT '.$pgstrt.$q['posts_per_page'];
} else { // we're ignoring $page and using 'offset'
$pgstrt = $q['offset'] . ', ';
$limits = 'LIMIT ' . $pgstrt . $q['posts_per_page'];
}
} elseif ($q['what_to_show'] == 'days') {
$startrow = $q['posts_per_page'] * (intval($page)-1);
$start_date = $wpdb->get_var("SELECT max(post_date) FROM $wpdb->posts $join WHERE (1=1) $where GROUP BY year(post_date), month(post_date), dayofmonth(post_date) ORDER BY post_date DESC LIMIT $startrow,1");
$endrow = $startrow + $q['posts_per_page'] - 1;
$end_date = $wpdb->get_var("SELECT min(post_date) FROM $wpdb->posts $join WHERE (1=1) $where GROUP BY year(post_date), month(post_date), dayofmonth(post_date) ORDER BY post_date DESC LIMIT $endrow,1");
if ($page > 1) {
$where .= " AND post_date >= '$end_date' AND post_date <= '$start_date'";
} else {
$where .= " AND post_date >= '$end_date'";
}
}
}
// Apply post-paging filters on where and join. Only plugins that
// manipulate paging queries should use these hooks.
$where = apply_filters('posts_where_paged', $where);
$groupby = " $wpdb->posts.ID ";
$groupby = apply_filters('posts_groupby', $groupby);
$join = apply_filters('posts_join_paged', $join);
$orderby = "post_" . $q['orderby'];
$orderby = apply_filters('posts_orderby', $orderby);
$request = " SELECT $distinct * FROM $wpdb->posts $join WHERE 1=1" . $where . " GROUP BY " . $groupby . " ORDER BY " . $orderby . " $limits";
$this->request = apply_filters('posts_request', $request);
$this->posts = $wpdb->get_results($this->request);
// Check post status to determine if post should be displayed.
if ( !empty($this->posts) && $this->is_single ) {
$status = get_post_status($this->posts[0]);
if ( ('publish' != $status) && ('static' != $status) ) {
if ( ! (isset($user_ID) && ('' != intval($user_ID))) ) {
// User must be logged in to view unpublished posts.
$this->posts = array();
} else {
if ('draft' == $status) {
// User must have edit permissions on the draft to preview.
if (! current_user_can('edit_post', $this->posts[0]->ID)) {
$this->posts = array();
} else {
$this->is_preview = true;
$this->posts[0]->post_date = current_time('mysql');
}
} else {
if (! current_user_can('read_post', $this->posts[0]->ID))
$this->posts = array();
}
}
} else {
if (mysql2date('U', $this->posts[0]->post_date_gmt) > mysql2date('U', $now)) { //it's future dated
$this->is_preview = true;
if (!current_user_can('edit_post', $this->posts[0]->ID)) {
$this->posts = array ( );
}
}
}
}
update_post_caches($this->posts);
$this->posts = apply_filters('the_posts', $this->posts);
$this->post_count = count($this->posts);
if ($this->post_count > 0) {
$this->post = $this->posts[0];
}
// Save any changes made to the query vars.
$this->query_vars = $q;
return $this->posts;
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:101,代码来源:classes.php
示例8: get_posts
function get_posts($args) {
global $wpdb;
if ( is_array($args) )
$r = &$args;
else
parse_str($args, $r);
$defaults = array('numberposts' => 5, 'offset' => 0, 'category' => 0,
'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => '',
'meta_key' => '', 'meta_value' =>'', 'post_type' => 'post', 'post_status' => 'publish', 'post_parent' => 0);
$r = array_merge($defaults, $r);
extract($r);
$numberposts = (int) $numberposts;
$offset = (int) $offset;
$category = (int) $category;
$post_parent = (int) $post_parent;
$inclusions = '';
if ( !empty($include) ) {
$offset = 0; //ignore offset, category, exclude, meta_key, and meta_value, post_parent if using include
$category = 0;
$exclude = '';
$meta_key = '';
$meta_value = '';
$post_parent = 0;
$incposts = preg_split('/[\s,]+/',$include);
$numberposts = count($incposts); // only the number of posts included
if ( count($incposts) ) {
foreach ( $incposts as $incpost ) {
if (empty($inclusions))
$inclusions = ' AND ( ID = ' . intval($incpost) . ' ';
else
$inclusions .= ' OR ID = ' . intval($incpost) . ' ';
}
}
}
if (!empty($inclusions))
$inclusions .= ')';
$exclusions = '';
if ( !empty($exclude) ) {
$exposts = preg_split('/[\s,]+/',$exclude);
if ( count($exposts) ) {
foreach ( $exposts as $expost ) {
if (empty($exclusions))
$exclusions = ' AND ( ID <> ' . intval($expost) . ' ';
else
$exclusions .= ' AND ID <> ' . intval($expost) . ' ';
}
}
}
if (!empty($exclusions))
$exclusions .= ')';
$query ="SELECT DISTINCT * FROM $wpdb->posts " ;
$query .= ( empty( $category ) ? "" : ", $wpdb->post2cat " );
$query .= ( empty( $meta_key ) ? "" : ", $wpdb->postmeta " );
$query .= " WHERE (post_type = 'post' AND post_status = 'publish') $exclusions $inclusions ";
$query .= ( empty( $category ) ? "" : "AND ($wpdb->posts.ID = $wpdb->post2cat.post_id AND $wpdb->post2cat.category_id = " . $category. ") " );
$query .= ( empty( $meta_key ) | empty($meta_value) ? "" : " AND ($wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key = '$meta_key' AND $wpdb->postmeta.meta_value = '$meta_value' )" );
$query .= " GROUP BY $wpdb->posts.ID ORDER BY " . $orderby . " " . $order . " LIMIT " . $offset . ',' . $numberposts;
$query = "SELECT DISTINCT * FROM $wpdb->posts ";
$query .= empty( $category ) ? '' : ", $wpdb->post2cat ";
$query .= empty( $meta_key ) ? '' : ", $wpdb->postmeta ";
$query .= " WHERE 1=1 ";
$query .= empty( $post_type ) ? '' : "AND post_type = '$post_type' ";
$query .= empty( $post_status ) ? '' : "AND post_status = '$post_status' ";
$query .= "$exclusions $inclusions " ;
$query .= empty( $category ) ? '' : "AND ($wpdb->posts.ID = $wpdb->post2cat.post_id AND $wpdb->post2cat.category_id = " . $category. ") ";
$query .= empty( $post_parent ) ? '' : "AND $wpdb->posts.post_parent = '$post_parent' ";
$query .= empty( $meta_key ) | empty($meta_value) ? '' : " AND ($wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key = '$meta_key' AND $wpdb->postmeta.meta_value = '$meta_value' )";
$query .= " GROUP BY $wpdb->posts.ID ORDER BY " . $orderby . ' ' . $order;
if ( 0 < $numberposts )
$query .= " LIMIT " . $offset . ',' . $numberposts;
$posts = $wpdb->get_results($query);
update_post_caches($posts);
return $posts;
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:83,代码来源:post.php
示例9: reloadGlobals
function reloadGlobals()
{
global $post;
global $wp_query;
global $id;
/*
* Not sure what is better out of the twop options below. this:
*/
wp_reset_query();
/*
* or this:
*/
//$wp_query->the_post();
//$wp_query->rewind_posts();
/*
* Acheives almost the same thing, if problems arise, investigate alternatives.
*/
update_post_caches($wp_query->posts);
/*if($wp_query==$this->page_query){
print('== supercats if off ==');
if($this->page_query->post->ID!=$id)
{
print_r('something is amiss '.$this->page_query->post->ID.'!='.$id);
}
}elseif($this->cat_query)print('== supercats is on ==');
else print('supercats is broken');
*/
}
开发者ID:ramblinollie,项目名称:VAM,代码行数:28,代码来源:DF_SuperCatsPlugin.class.php
示例10: get_settings
//.........这里部分代码省略.........
// Used to filter values
$allowed_keys = array('author', 'date', 'category', 'title');
$q['orderby'] = urldecode($q['orderby']);
$q['orderby'] = addslashes_gpc($q['orderby']);
$orderby_array = explode(' ', $q['orderby']);
if (!in_array($orderby_array[0], $allowed_keys)) {
$orderby_array[0] = 'date';
}
$q['orderby'] = $orderby_array[0] . ' ' . $q['order'];
if (count($orderby_array) > 1) {
for ($i = 1; $i < count($orderby_array); $i = $i + 1) {
// Only allow certain values for safety
if (in_array($orderby_array[$i], $allowed_keys)) {
$q['orderby'] .= ',post_' . $orderby_array[$i] . ' ' . $q['order'];
}
}
}
}
$now = gmdate('Y-m-d H:i:59');
if ($pagenow != 'post.php' && $pagenow != 'edit.php') {
$where .= " AND post_date_gmt <= '{$now}'";
$distinct = 'DISTINCT';
}
if ($this->is_page) {
$where .= ' AND (post_status = "static")';
} elseif ($this->is_single) {
$where .= ' AND (post_status != "static")';
} else {
$where .= ' AND (post_status = "publish"';
if (isset($user_ID) && '' != intval($user_ID)) {
$where .= " OR post_author = {$user_ID} AND post_status != 'draft' AND post_status != 'static')";
} else {
$where .= ')';
}
}
// Apply filters on where and join prior to paging so that any
// manipulations to them are reflected in the paging by day queries.
$where = apply_filters('posts_where', $where);
$join = apply_filters('posts_join', $join);
// Paging
if (empty($q['nopaging']) && !$this->is_single) {
$page = $q['paged'];
if (empty($page)) {
$page = 1;
}
if ($q['what_to_show'] == 'posts') {
$pgstrt = '';
$pgstrt = (intval($page) - 1) * $q['posts_per_page'] . ', ';
$limits = 'LIMIT ' . $pgstrt . $q['posts_per_page'];
} elseif ($q['what_to_show'] == 'days') {
$startrow = $q['posts_per_page'] * (intval($page) - 1);
$start_date = $wpdb->get_var("SELECT max(post_date) FROM {$wpdb->posts} {$join} WHERE (1=1) {$where} GROUP BY year(post_date), month(post_date), dayofmonth(post_date) ORDER BY post_date DESC LIMIT {$startrow},1");
$endrow = $startrow + $q['posts_per_page'] - 1;
$end_date = $wpdb->get_var("SELECT min(post_date) FROM {$wpdb->posts} {$join} WHERE (1=1) {$where} GROUP BY year(post_date), month(post_date), dayofmonth(post_date) ORDER BY post_date DESC LIMIT {$endrow},1");
if ($page > 1) {
$where .= " AND post_date >= '{$end_date}' AND post_date <= '{$start_date}'";
} else {
$where .= " AND post_date >= '{$end_date}'";
}
}
}
// Apply post-paging filters on where and join. Only plugins that
// manipulate paging queries should use these hooks.
$where = apply_filters('posts_where_paged', $where);
$where .= " GROUP BY {$wpdb->posts}.ID";
$join = apply_filters('posts_join_paged', $join);
$orderby = "post_" . $q['orderby'];
$orderby = apply_filters('posts_orderby', $orderby);
$request = " SELECT {$distinct} * FROM {$wpdb->posts} {$join} WHERE 1=1" . $where . " ORDER BY " . $orderby . " {$limits}";
$this->posts = $wpdb->get_results($request);
// Check post status to determine if post should be displayed.
if ($this->is_single) {
if ('publish' != $this->posts[0]->post_status) {
if (!(isset($user_ID) && '' != intval($user_ID))) {
// User must be logged in to view unpublished posts.
$this->posts = array();
} else {
if ('draft' == $this->posts[0]->post_status) {
// User must have edit permissions on the draft to preview.
if (!user_can_edit_post($user_ID, $this->posts[0]->ID)) {
$this->posts = array();
}
} elseif ('private' == $this->posts[0]->post_status) {
if ($this->posts[0]->post_author != $user_ID) {
$this->posts = array();
}
}
}
}
}
$this->posts = apply_filters('the_posts', $this->posts);
$this->post_count = count($this->posts);
if ($this->post_count > 0) {
$this->post = $this->posts[0];
}
update_post_caches($this->posts);
// Save any changes made to the query vars.
$this->query_vars = $q;
return $this->posts;
}
开发者ID:BackupTheBerlios,项目名称:steampress-svn,代码行数:101,代码来源:classes.php
示例11: get_posts
//.........这里部分代码省略.........
$climits = apply_filters_ref_array('comment_feed_limits', array( 'LIMIT ' . get_option('posts_per_rss'), &$this ) );
$comments_request = "SELECT $wpdb->comments.* FROM $wpdb->comments $cjoin $cwhere $cgroupby $corderby $climits";
$this->comments = $wpdb->get_results($comments_request);
$this->comment_count = count($this->comments);
}
// Check post status to determine if post should be displayed.
if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) {
$status = get_post_status($this->posts[0]);
$post_status_obj = get_post_status_object($status);
//$type = get_post_type($this->posts[0]);
if ( !$post_status_obj->public ) {
if ( ! is_user_logged_in() ) {
// User must be logged in to view unpublished posts.
$this->posts = array();
} else {
if ( $post_status_obj->protected ) {
// User must have edit permissions on the draft to preview.
if ( ! current_user_can($edit_cap, $this->posts[0]->ID) ) {
$this->posts = array();
} else {
$this->is_preview = true;
if ( 'future' != $status )
$this->posts[0]->post_date = current_time('mysql');
}
} elseif ( $post_status_obj->private ) {
if ( ! current_user_can($read_cap, $this->posts[0]->ID) )
$this->posts = array();
} else {
$this->posts = array();
}
}
}
if ( $this->is_preview && $this->posts && current_user_can( $edit_cap, $this->posts[0]->ID ) )
$this->posts[0] = get_post( apply_filters_ref_array( 'the_preview', array( $this->posts[0], &$this ) ) );
}
// Put sticky posts at the top of the posts array
$sticky_posts = get_option('sticky_posts');
if ( $this->is_home && $page <= 1 && is_array($sticky_posts) && !empty($sticky_posts) && !$q['ignore_sticky_posts'] ) {
$num_posts = count($this->posts);
$sticky_offset = 0;
// Loop over posts and relocate stickies to the front.
for ( $i = 0; $i < $num_posts; $i++ ) {
if ( in_array($this->posts[$i]->ID, $sticky_posts) ) {
$sticky_post = $this->posts[$i];
// Remove sticky from current position
array_splice($this->posts, $i, 1);
// Move to front, after other stickies
array_splice($this->posts, $sticky_offset, 0, array($sticky_post));
// Increment the sticky offset. The next sticky will be placed at this offset.
$sticky_offset++;
// Remove post from sticky posts array
$offset = array_search($sticky_post->ID, $sticky_posts);
unset( $sticky_posts[$offset] );
}
}
// If any posts have been excluded specifically, Ignore those that are sticky.
if ( !empty($sticky_posts) && !empty($q['post__not_in']) )
$sticky_posts = array_diff($sticky_posts, $q['post__not_in']);
// Fetch sticky posts that weren't in the query results
if ( !empty($sticky_posts) ) {
$stickies = get_posts( array(
'post__in' => $sticky_posts,
'post_type' => $post_type,
'post_status' => 'publish',
'nopaging' => true
) );
foreach ( $stickies as $sticky_post ) {
array_splice( $this->posts, $sticky_offset, 0, array( $sticky_post ) );
$sticky_offset++;
}
}
}
if ( !$q['suppress_filters'] )
$this->posts = apply_filters_ref_array('the_posts', array( $this->posts, &$this ) );
// Ensure that any posts added/modified via one of the filters above are
// of the type WP_Post and are filtered.
if ( $this->posts ) {
$this->post_count = count( $this->posts );
$this->posts = array_map( 'get_post', $this->posts );
if ( $q['cache_results'] )
update_post_caches($this->posts, $post_type, $q['update_post_term_cache'], $q['update_post_meta_cache']);
$this->post = reset( $this->posts );
} else {
$this->post_count = 0;
$this->posts = array();
}
return $this->posts;
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:101,代码来源:query.php
示例12: dito_doDiarioSidebar
function dito_doDiarioSidebar()
{
global $post;
echo '<div class="boxesBox"><h2 class="blue">Ultime dal Diario</h2>';
$my_query = new WP_Query("cat=138&showposts=2");
while ($my_query->have_posts()) {
$my_query->the_post();
update_post_caches($posts);
$title = $post->post_title;
$link = get_permalink($post->ID);
$shortContentText = $post->post_content;
$shortContentText = strip_tags($shortContentText);
$shortContentText = substr($shortContentText, 0, 800);
$lastSpaceOnEarth = strpos($shortContentText, '.', 10);
$shortContentText = substr($shortContentText, 0, $lastSpaceOnEarth + 1);
$shortContentText = str_replace(".", ".<br/>", $shortContentText);
echo '<div class="boxesSecondLine"><a href="' . $link . '">' . $title . '</a><br/>' . $shortContentText . '</div>';
}
rewind_posts();
if (!is_category()) {
echo '<div class="boxesSecondLine segnalaRight"> <p class="segnala2"><a href="' . get_bloginfo('url') . '/category/dito-in-missione" class="segnala">Tutto il Diario</a></p></div></div>';
}
}
开发者ID:rogopag,项目名称:area,代码行数:23,代码来源:functions.php
示例13: ultimate_get_posts
function ultimate_get_posts()
{
global $wpdb, $table_prefix, $posts, $id, $wp_query, $request, $utw, $typelimitsql;
$tabletags = $table_prefix . 'tags';
$tablepost2tag = $table_prefix . "post2tag";
$or_query = false;
$tags = get_query_var("tag");
$tagset = explode(" ", $tags);
if (count($tagset) == 1) {
$tagset = explode("|", $tags);
$or_query = true;
}
$tags = array();
foreach ($tagset as $tag) {
$tags[] = "'" . stripslashes($utw->GetCanonicalTag($tag)) . "'";
}
$tags = array_unique($tags);
$tagcount = count($tags);
if (strpos($request, "HAVING COUNT(ID)") == false && !$or_query) {
$request = preg_replace("/ORDER BY/", "HAVING COUNT(ID) = {$tagcount} ORDER BY", $request);
}
$request = preg_replace("/post_type = 'post'/", "{$typelimitsql}", $request);
$posts = $wpdb->get_results($request);
// As requested by Splee and copperleaf
$wp_query->is_home = false;
// Thanks Mark! http://txfx.net/
$posts = apply_filters('the_posts', $posts);
$wp_query->posts = $posts;
$wp_query->post_count = count($posts);
update_post_caches($posts);
if ($wp_query->post_count > 0) {
$wp_query->post = $wp_query->posts[0];
// Thanks Bill! http://www.copperleaf.org
$wp_query->is_404 = false;
}
}
开发者ID:jbogota,项目名称:blog-king,代码行数:36,代码来源:ultimate-tag-warrior-core.php
示例14: do_action_ref_array
//.........这里部分代码省略.........
$cjoin = "LEFT JOIN {$wpdb->posts} ON ( {$wpdb->comments}.comment_post_ID = {$wpdb->posts}.ID )";
$cwhere = "WHERE post_status = 'publish' AND comment_approved = '1'";
$cgroupby = '';
}
$cjoin = apply_filters('comment_feed_join', $cjoin);
$cwhere = apply_filters('comment_feed_where', $cwhere);
$cgroupby = apply_filters('comment_feed_groupby', $cgroupby);
$this->comments = (array) $wpdb->get_results("SELECT {$distinct} {$wpdb->comments}.* FROM {$wpdb->comments} {$cjoin} {$cwhere} {$cgroupby} ORDER BY comment_date_gmt DESC LIMIT " . get_option('posts_per_rss'));
$this->comment_count = count($this->comments);
$post_ids = array();
foreach ($this->comments as $comment) {
$post_ids[] = (int) $comment->comment_post_ID;
}
$post_ids = join(',', $post_ids);
$join = '';
if ($post_ids) {
$where = "AND {$wpdb->posts}.ID IN ({$post_ids}) ";
} else {
$where = "AND 0";
}
}
// Apply post-paging filters on where and join. Only plugins that
// manipulate paging queries should use these hooks.
// Announce current selection parameters. For use by caching plugins.
do_action('posts_selection', $where . $groupby . $q['orderby'] . $limits . $join);
$where = apply_filters('posts_where_paged', $where);
$groupby = apply_filters('posts_groupby', $groupby);
if (!empty($groupby)) {
$groupby = 'GROUP BY ' . $groupby;
}
$join = apply_filters('posts_join_paged', $join);
$orderby = apply_filters('posts_orderby', $q['orderby']);
if (!empty($orderby)) {
$orderby = 'ORDER BY ' . $orderby;
}
$distinct = apply_filters('posts_distinct', $distinct);
$fields = apply_filters('posts_fields', "{$wpdb->posts}.*");
$limits = apply_filters('post_limits', $limits);
$found_rows = '';
if (!empty($limits)) {
$found_rows = 'SQL_CALC_FOUND_ROWS';
}
$request = " SELECT {$found_rows} {$distinct} {$fields} FROM {$wpdb->posts} {$join} WHERE 1=1 {$where} {$groupby} {$orderby} {$limits}";
$this->request = apply_filters('posts_request', $request);
$this->posts = $wpdb->get_results($this->request);
// Raw results filter. Prior to status checks.
$this->posts = apply_filters('posts_results', $this->posts);
if ($this->is_comment_feed && $this->is_singular) {
$cjoin = apply_filters('comment_feed_join', '');
$cwhere = apply_filters('comment_feed_where', "WHERE comment_post_ID = {$this->posts[0]->ID} AND comment_approved = '1'");
$comments_request = "SELECT {$wpdb->comments}.* FROM {$wpdb->comments} {$cjoin} {$cwhere} ORDER BY comment_date_gmt DESC LIMIT " . get_option('posts_per_rss');
$this->comments = $wpdb->get_results($comments_request);
$this->comment_count = count($this->comments);
}
if (!empty($limits)) {
$found_posts_query = apply_filters('found_posts_query', 'SELECT FOUND_ROWS()');
$this->found_posts = $wpdb->get_var($found_posts_query);
$this->found_posts = apply_filters('found_posts', $this->found_posts);
$this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']);
}
// Check post status to determine if post should be displayed.
if (!empty($this->posts) && ($this->is_single || $this->is_page)) {
$status = get_post_status($this->posts[0]);
//$type = get_post_type($this->posts[0]);
if ('publish' != $status) {
if (!is_user_logged_in()) {
// User must be logged in to view unpublished posts.
$this->posts = array();
} else {
if (in_array($status, array('draft', 'pending'))) {
// User must have edit permissions on the draft to preview.
if (!current_user_can('edit_post', $this->posts[0]->ID)) {
$this->posts = array();
} else {
$this->is_preview = true;
$this->posts[0]->post_date = current_time('mysql');
}
} else {
if ('future' == $status) {
$this->is_preview = true;
if (!current_user_can('edit_post', $this->posts[0]->ID)) {
$this->posts = array();
}
} else {
if (!current_user_can('read_post', $this->posts[0]->ID)) {
$this->posts = array();
}
}
}
}
}
}
$this->posts = apply_filters('the_posts', $this->posts);
update_post_caches($this->posts);
$this->post_count = count($this->posts);
if ($this->post_count > 0) {
$this->post = $this->posts[0];
}
return $this->posts;
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:101,代码来源:query.php
示例 |
请发表评论