summaryrefslogtreecommitdiffstats
path: root/wp-includes/query.php
diff options
context:
space:
mode:
Diffstat (limited to 'wp-includes/query.php')
-rw-r--r--wp-includes/query.php117
1 files changed, 73 insertions, 44 deletions
diff --git a/wp-includes/query.php b/wp-includes/query.php
index 05415aa..79b6ba1 100644
--- a/wp-includes/query.php
+++ b/wp-includes/query.php
@@ -200,7 +200,7 @@ function is_single ($post = '') {
function is_singular() {
global $wp_query;
- return $wp_query->is_singular;
+ return $wp_query->is_singular;
}
function is_time () {
@@ -285,7 +285,7 @@ class WP_Query {
var $current_post = -1;
var $in_the_loop = false;
var $post;
-
+
var $comments;
var $comment_count = 0;
var $current_comment = -1;
@@ -360,7 +360,7 @@ class WP_Query {
function parse_query_vars() {
$this->parse_query('');
}
-
+
function fill_query_vars($array) {
$keys = array(
'error'
@@ -395,7 +395,7 @@ class WP_Query {
if ( !isset($array[$key]))
$array[$key] = '';
}
-
+
return $array;
}
@@ -410,9 +410,9 @@ class WP_Query {
$this->query = $query;
$this->query_vars = $qv;
}
-
+
$qv = $this->fill_query_vars($qv);
-
+
if ( ! empty($qv['robots']) ) {
$this->is_robots = true;
return;
@@ -561,21 +561,56 @@ class WP_Query {
$this->is_admin = true;
}
- if ( $this->is_single || $this->is_page || $this->is_attachment )
- $this->is_singular = true;
-
if ( false !== strpos($qv['feed'], 'comments-') ) {
$this->query_vars['feed'] = $qv['feed'] = str_replace('comments-', '', $qv['feed']);
$qv['withcomments'] = 1;
}
- if ( $this->is_feed && (!empty($qv['withcomments']) || ( empty($qv['withoutcomments']) && $this->is_singular ) ) )
+ $this->is_singular = $this->is_single || $this->is_page || $this->is_attachment;
+
+ if ( $this->is_feed && ( !empty($qv['withcomments']) || ( empty($qv['withoutcomments']) && $this->is_singular ) ) )
$this->is_comment_feed = true;
- if ( ! ($this->is_singular || $this->is_archive || $this->is_search || $this->is_feed || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_comments_popup)) {
+ if ( !( $this->is_singular || $this->is_archive || $this->is_search || $this->is_feed || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_comments_popup ) ) {
$this->is_home = true;
}
+ // Correct is_* for page_on_front and page_for_posts
+ if ( $this->is_home && ( empty($this->query) || $qv['preview'] == 'true' ) && 'page' == get_option('show_on_front') && get_option('page_on_front') ) {
+ $this->is_page = true;
+ $this->is_home = false;
+ $this->query_vars['page_id'] = get_option('page_on_front');
+ }
+
+ if ( '' != $qv['pagename'] ) {
+ $this->queried_object =& get_page_by_path($qv['pagename']);
+ if ( !empty($this->queried_object) )
+ $this->queried_object_id = $this->queried_object->ID;
+ else
+ unset($this->queried_object);
+
+ if ( 'page' == get_option('show_on_front') && isset($this->queried_object_id) && $this->queried_object_id == get_option('page_for_posts') ) {
+ $this->is_page = false;
+ $this->is_home = true;
+ $this->is_posts_page = true;
+ }
+ }
+
+ if ( '' != $qv['page_id'] && 0 != intval($qv['page_id']) ) {
+ $this->query_vars['page_id'] = intval($qv['page_id']);
+ if ( 'page' == get_option('show_on_front') && $qv['page_id'] == get_option('page_for_posts') ) {
+ $this->is_page = false;
+ $this->is_home = true;
+ $this->is_posts_page = true;
+ }
+ }
+
+ if ( $this->is_posts_page && !$qv['withcomments'] )
+ $this->is_comment_feed = false;
+
+ $this->is_singular = $this->is_single || $this->is_page || $this->is_attachment;
+ // Done correcting is_* for page_on_front and page_for_posts
+
if ( !empty($query) ) {
do_action_ref_array('parse_query', array(&$this));
}
@@ -609,7 +644,7 @@ class WP_Query {
// Shorthand.
$q = &$this->query_vars;
-
+
$q = $this->fill_query_vars($q);
// First let's clear some variables
@@ -724,18 +759,17 @@ class WP_Query {
$q['name'] = sanitize_title($q['name']);
$where .= " AND post_name = '" . $q['name'] . "'";
} else if ('' != $q['pagename']) {
- $reqpage = get_page_by_path($q['pagename']);
- if ( !empty($reqpage) )
- $reqpage = $reqpage->ID;
- else
- $reqpage = 0;
+ if ( isset($this->queried_object_id) )
+ $reqpage = $this->queried_object_id;
+ else {
+ $reqpage = get_page_by_path($q['pagename']);
+ if ( !empty($reqpage) )
+ $reqpage = $reqpage->ID;
+ else
+ $reqpage = 0;
+ }
- if ( ('page' == get_option('show_on_front') ) && ( $reqpage == get_option('page_for_posts') ) ) {
- $this->is_singular = false;
- $this->is_page = false;
- $this->is_home = true;
- $this->is_posts_page = true;
- } else {
+ if ( ('page' != get_option('show_on_front') ) || ( $reqpage != get_option('page_for_posts') ) ) {
$q['pagename'] = str_replace('%2F', '/', urlencode(urldecode($q['pagename'])));
$page_paths = '/' . trim($q['pagename'], '/');
$q['pagename'] = sanitize_title(basename($page_paths));
@@ -770,12 +804,7 @@ class WP_Query {
if (($q['page_id'] != '') && (intval($q['page_id']) != 0)) {
$q['page_id'] = intval($q['page_id']);
- if ( ('page' == get_option('show_on_front') ) && ( $q['page_id'] == get_option('page_for_posts') ) ) {
- $this->is_singular = false;
- $this->is_page = false;
- $this->is_home = true;
- $this->is_posts_page = true;
- } else {
+ if ( ('page' != get_option('show_on_front') ) || ( $q['page_id'] != get_option('page_for_posts') ) ) {
$q['p'] = $q['page_id'];
$where = ' AND ID = '.$q['page_id'];
}
@@ -1001,7 +1030,7 @@ class WP_Query {
$limits = 'LIMIT ' . $pgstrt . $q['posts_per_page'];
}
}
-
+
// Comments feeds
if ( $this->is_comment_feed && ( $this->is_archive || $this->is_search || !$this->is_singular ) ) {
if ( $this->is_archive || $this->is_search ) {
@@ -1013,19 +1042,19 @@ class WP_Query {
$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_settings('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 )
@@ -1061,14 +1090,14 @@ class WP_Query {
$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]);
@@ -1148,34 +1177,34 @@ class WP_Query {
$this->post = $this->posts[0];
}
}
-
+
function next_comment() {
$this->current_comment++;
-
+
$this->comment = $this->comments[$this->current_comment];
return $this->comment;
}
-
+
function the_comment() {
global $comment;
-
+
$comment = $this->next_comment();
-
+
if ($this->current_comment == 0) {
do_action('comment_loop_start');
}
}
-
+
function have_comments() {
if ($this->current_comment + 1 < $this->comment_count) {
return true;
} elseif ($this->current_comment + 1 == $this->comment_count) {
$this->rewind_comments();
}
-
+
return false;
}
-
+
function rewind_comments() {
$this->current_comment = -1;
if ($this->comment_count > 0) {