wp/wp-includes/query.php
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * WordPress Query API
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * The query API attempts to get which part of WordPress the user is on. It
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * also provides functionality for getting URL query information.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     8
 * @link https://codex.wordpress.org/The_Loop More information on The Loop.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 * @subpackage Query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 * Retrieve variable in the WP_Query class.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
 * @see WP_Query::get()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    21
 * @param string $var       The variable key to retrieve.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    22
 * @param mixed  $default   Value to return if the query variable is not set. Default ''.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
 * @return mixed
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    25
function get_query_var( $var, $default = '' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    28
	return $wp_query->get( $var, $default );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
 * Retrieve the currently-queried object. Wrapper for $wp_query->get_queried_object()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
 * @uses WP_Query::get_queried_object
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
 * @return object
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
function get_queried_object() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
	return $wp_query->get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
 * Retrieve ID of the current queried object. Wrapper for $wp_query->get_queried_object_id()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
 * @uses WP_Query::get_queried_object_id()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
 * @return int
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
function get_queried_object_id() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
	return $wp_query->get_queried_object_id();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
 * Set query variable.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
 * @see WP_Query::set()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
 * @param string $var Query variable key.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
 * @param mixed $value
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
 * @return null
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
function set_query_var($var, $value) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
	return $wp_query->set($var, $value);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
 * Set up The Loop with query parameters.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
 * This will override the current WordPress Loop and shouldn't be used more than
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
 * once. This must not be used within the WordPress Loop.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
 * @param string $query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
 * @return array List of posts
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
function query_posts($query) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
	$GLOBALS['wp_query'] = new WP_Query();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
	return $GLOBALS['wp_query']->query($query);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
 * Destroy the previous query and set up a new query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
 * This should be used after {@link query_posts()} and before another {@link
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
 * query_posts()}. This will remove obscure bugs that occur when the previous
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
 * wp_query object is not destroyed properly before another is set up.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
function wp_reset_query() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
	$GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
	wp_reset_postdata();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
 * After looping through a separate query, this function restores
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
 * the $post global to the current post in the main query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
function wp_reset_postdata() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
	global $wp_query;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   119
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   120
	if ( isset( $wp_query ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   121
		$wp_query->reset_postdata();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   122
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
/*
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
 * Query type checks.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
 * Is the query for an existing archive page?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
 * Month, Year, Category, Author, Post Type archive...
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
 * @see WP_Query::is_archive()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
function is_archive() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
	if ( ! isset( $wp_query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
	return $wp_query->is_archive();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
 * Is the query for an existing post type archive page?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
 * @see WP_Query::is_post_type_archive()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
 * @param mixed $post_types Optional. Post type or array of posts types to check against.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
function is_post_type_archive( $post_types = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
	if ( ! isset( $wp_query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
	return $wp_query->is_post_type_archive( $post_types );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
 * Is the query for an existing attachment page?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
 * @see WP_Query::is_attachment()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   179
 * @param int|string|array|object $attachment Attachment ID, title, slug, or array of such.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   182
function is_attachment( $attachment = '' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
	if ( ! isset( $wp_query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   190
	return $wp_query->is_attachment( $attachment );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
 * Is the query for an existing author archive page?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
 * If the $author parameter is specified, this function will additionally
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
 * check if the query is for one of the authors specified.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
 * @see WP_Query::is_author()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
 * @param mixed $author Optional. User ID, nickname, nicename, or array of User IDs, nicknames, and nicenames
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
function is_author( $author = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
	if ( ! isset( $wp_query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
	return $wp_query->is_author( $author );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
 * Is the query for an existing category archive page?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
 * If the $category parameter is specified, this function will additionally
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
 * check if the query is for one of the categories specified.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
 * @see WP_Query::is_category()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
 * @param mixed $category Optional. Category ID, name, slug, or array of Category IDs, names, and slugs.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
function is_category( $category = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
	if ( ! isset( $wp_query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
	return $wp_query->is_category( $category );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
 * Is the query for an existing tag archive page?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
 * If the $tag parameter is specified, this function will additionally
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
 * check if the query is for one of the tags specified.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
 * @see WP_Query::is_tag()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
 * @param mixed $tag Optional. Tag ID, name, slug, or array of Tag IDs, names, and slugs.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
function is_tag( $tag = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
	if ( ! isset( $wp_query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
	return $wp_query->is_tag( $tag );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
 * Is the query for an existing taxonomy archive page?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
 * If the $taxonomy parameter is specified, this function will additionally
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
 * check if the query is for that specific $taxonomy.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
 * If the $term parameter is specified in addition to the $taxonomy parameter,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
 * this function will additionally check if the query is for one of the terms
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
 * specified.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
 * @see WP_Query::is_tax()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   279
 * @param string|array $taxonomy Optional. Taxonomy slug or slugs.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   280
 * @param int|string|array $term Optional. Term ID, name, slug or array of Term IDs, names, and slugs.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
function is_tax( $taxonomy = '', $term = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
	if ( ! isset( $wp_query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
	return $wp_query->is_tax( $taxonomy, $term );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
 * Whether the current URL is within the comments popup window.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
 * @see WP_Query::is_comments_popup()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
function is_comments_popup() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
	if ( ! isset( $wp_query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
	return $wp_query->is_comments_popup();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
 * Is the query for an existing date archive?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
 * @see WP_Query::is_date()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
function is_date() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
	if ( ! isset( $wp_query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
	return $wp_query->is_date();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
 * Is the query for an existing day archive?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
 * @see WP_Query::is_day()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
function is_day() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
	if ( ! isset( $wp_query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
	return $wp_query->is_day();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
 * Is the query for a feed?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
 * @see WP_Query::is_feed()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
 * @param string|array $feeds Optional feed types to check.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
function is_feed( $feeds = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
	if ( ! isset( $wp_query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
	return $wp_query->is_feed( $feeds );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
 * Is the query for a comments feed?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
 * @see WP_Query::is_comments_feed()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
function is_comment_feed() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
	if ( ! isset( $wp_query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
	return $wp_query->is_comment_feed();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
 * Is the query for the front page of the site?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
 * This is for what is displayed at your site's main URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
 * Depends on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_on_front'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
 * If you set a static page for the front page of your site, this function will return
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
 * true when viewing that page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
 * Otherwise the same as @see is_home()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
 * @see WP_Query::is_front_page()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
 * @return bool True, if front of site.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
function is_front_page() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
	if ( ! isset( $wp_query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
	return $wp_query->is_front_page();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
 * Is the query for the blog homepage?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
 * This is the page which shows the time based blog content of your site.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
 * Depends on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_for_posts'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
 * If you set a static page for the front page of your site, this function will return
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
 * true only on the page you set as the "Posts page".
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
 * @see is_front_page()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
 * @see WP_Query::is_home()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
 * @return bool True if blog view homepage.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
function is_home() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
	if ( ! isset( $wp_query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
	return $wp_query->is_home();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
 * Is the query for an existing month archive?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
 * @see WP_Query::is_month()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
function is_month() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
	if ( ! isset( $wp_query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
	return $wp_query->is_month();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
 * Is the query for an existing single page?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
 * If the $page parameter is specified, this function will additionally
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
 * check if the query is for one of the pages specified.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
 * @see is_single()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
 * @see is_singular()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
 * @see WP_Query::is_page()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
 * @param mixed $page Page ID, title, slug, or array of such.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
function is_page( $page = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
	if ( ! isset( $wp_query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
	return $wp_query->is_page( $page );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
 * Is the query for paged result and not for the first page?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
 * @see WP_Query::is_paged()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
function is_paged() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
	if ( ! isset( $wp_query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
	return $wp_query->is_paged();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
 * Is the query for a post or page preview?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
 * @see WP_Query::is_preview()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
function is_preview() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   531
	if ( ! isset( $wp_query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
	return $wp_query->is_preview();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
 * Is the query for the robots file?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
 * @see WP_Query::is_robots()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
function is_robots() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
	if ( ! isset( $wp_query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
	return $wp_query->is_robots();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
 * Is the query for a search?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
 * @see WP_Query::is_search()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
function is_search() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
	if ( ! isset( $wp_query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
	return $wp_query->is_search();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
 * Is the query for an existing single post?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
 * Works for any post type, except attachments and pages
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
 * If the $post parameter is specified, this function will additionally
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
 * check if the query is for one of the Posts specified.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
 * @see is_page()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
 * @see is_singular()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
 * @see WP_Query::is_single()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
 * @param mixed $post Post ID, title, slug, or array of such.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
function is_single( $post = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   600
	if ( ! isset( $wp_query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   601
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
	return $wp_query->is_single( $post );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
 * Is the query for an existing single post of any post type (post, attachment, page, ... )?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
 * If the $post_types parameter is specified, this function will additionally
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
 * check if the query is for one of the Posts Types specified.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
 * @see is_page()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
 * @see is_single()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
 * @see WP_Query::is_singular()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   621
 * @param mixed $post_types Optional. Post Type or array of Post Types
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
function is_singular( $post_types = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
	if ( ! isset( $wp_query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
	return $wp_query->is_singular( $post_types );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
 * Is the query for a specific time?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
 * @see WP_Query::is_time()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
function is_time() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
	if ( ! isset( $wp_query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   652
	return $wp_query->is_time();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   655
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
 * Is the query for a trackback endpoint call?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
 * @see WP_Query::is_trackback()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
function is_trackback() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
	if ( ! isset( $wp_query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
	return $wp_query->is_trackback();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
 * Is the query for an existing year archive?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
 * @see WP_Query::is_year()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   683
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
function is_year() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
	if ( ! isset( $wp_query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
	return $wp_query->is_year();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
 * Is the query a 404 (returns no results)?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
 * @see WP_Query::is_404()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
function is_404() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
	if ( ! isset( $wp_query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
	return $wp_query->is_404();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
 * Is the query the main query?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   718
 * @since 3.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   719
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   720
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   721
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   722
function is_main_query() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
	if ( 'pre_get_posts' === current_filter() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   724
		$message = sprintf( __( 'In <code>%1$s</code>, use the <code>%2$s</code> method, not the <code>%3$s</code> function. See %4$s.' ),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   725
			'pre_get_posts', 'WP_Query::is_main_query()', 'is_main_query()', __( 'https://codex.wordpress.org/Function_Reference/is_main_query' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
		_doing_it_wrong( __FUNCTION__, $message, '3.7' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   729
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   730
	return $wp_query->is_main_query();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
/*
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
 * The Loop. Post loop control.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   736
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
 * Whether current WordPress query has results to loop over.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
 * @see WP_Query::have_posts()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   743
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   745
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   746
function have_posts() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   747
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   748
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   749
	return $wp_query->have_posts();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   751
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   752
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   753
 * Whether the caller is in the Loop.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   754
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   755
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   756
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   757
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
 * @return bool True if caller is within loop, false if loop hasn't started or ended.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
function in_the_loop() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
	return $wp_query->in_the_loop;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   764
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   766
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
 * Rewind the loop posts.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   768
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
 * @see WP_Query::rewind_posts()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   770
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   771
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   772
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   773
 * @return null
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   774
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   775
function rewind_posts() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   776
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   777
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   778
	return $wp_query->rewind_posts();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   779
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   780
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   781
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
 * Iterate the post index in the loop.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   783
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   784
 * @see WP_Query::the_post()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   785
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   786
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   787
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   788
function the_post() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   789
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   790
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   791
	$wp_query->the_post();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   792
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   793
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   794
/*
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   795
 * Comments loop.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   796
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   797
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   798
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   799
 * Whether there are comments to loop over.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
 * @see WP_Query::have_comments()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   802
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   804
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   805
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   806
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   807
function have_comments() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   808
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   809
	return $wp_query->have_comments();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   810
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   811
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   812
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   813
 * Iterate comment index in the comment loop.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   814
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   815
 * @see WP_Query::the_comment()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   816
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   817
 * @uses $wp_query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   818
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   819
 * @return object
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   820
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   821
function the_comment() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   822
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   823
	return $wp_query->the_comment();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   824
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   825
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   826
/*
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   827
 * WP_Query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   828
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   829
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   830
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   831
 * The WordPress Query class.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   832
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   833
 * @link https://codex.wordpress.org/Function_Reference/WP_Query Codex page.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   834
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   835
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   836
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   837
class WP_Query {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   838
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   839
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   840
	 * Query vars set by the user
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   841
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   842
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   843
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   844
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   845
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   846
	public $query;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   847
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   848
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   849
	 * Query vars, after parsing
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   850
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   851
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   852
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   853
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   854
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   855
	public $query_vars = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   856
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   857
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   858
	 * Taxonomy query, as passed to get_tax_sql()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   859
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   860
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   861
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   862
	 * @var object WP_Tax_Query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   863
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   864
	public $tax_query;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   865
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   866
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   867
	 * Metadata query container
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   868
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   869
	 * @since 3.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   870
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   871
	 * @var object WP_Meta_Query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   872
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   873
	public $meta_query = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   874
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   875
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   876
	 * Date query container
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   877
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   878
	 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   879
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   880
	 * @var object WP_Date_Query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   881
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   882
	public $date_query = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   883
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   884
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   885
	 * Holds the data for a single object that is queried.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   886
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   887
	 * Holds the contents of a post, page, category, attachment.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   888
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   889
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   890
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   891
	 * @var object|array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   892
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   893
	public $queried_object;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   894
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   895
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
	 * The ID of the queried object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   897
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   898
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   899
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   900
	 * @var int
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   901
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   902
	public $queried_object_id;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   903
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   904
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   905
	 * Get post database query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   906
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   907
	 * @since 2.0.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   908
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   909
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   910
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   911
	public $request;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   912
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   913
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   914
	 * List of posts.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   915
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   916
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   917
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   918
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   919
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   920
	public $posts;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   921
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   922
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   923
	 * The amount of posts for the current query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   924
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   925
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   926
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   927
	 * @var int
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   928
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   929
	public $post_count = 0;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   930
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   931
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   932
	 * Index of the current item in the loop.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   933
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   934
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   935
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   936
	 * @var int
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   937
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   938
	public $current_post = -1;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   939
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   940
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   941
	 * Whether the loop has started and the caller is in the loop.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   942
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   943
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   944
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   945
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   946
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   947
	public $in_the_loop = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   948
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   949
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   950
	 * The current post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   951
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   952
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   953
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   954
	 * @var WP_Post
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   955
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   956
	public $post;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   957
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   958
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   959
	 * The list of comments for current post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   960
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   961
	 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   962
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   963
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   964
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   965
	public $comments;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   966
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   967
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   968
	 * The amount of comments for the posts.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   969
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   970
	 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   971
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   972
	 * @var int
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   973
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   974
	public $comment_count = 0;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   975
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   976
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   977
	 * The index of the comment in the comment loop.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   978
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   979
	 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   980
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   981
	 * @var int
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   982
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   983
	public $current_comment = -1;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   984
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   985
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   986
	 * Current comment ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   987
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   988
	 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   989
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   990
	 * @var int
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   991
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   992
	public $comment;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   993
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   994
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   995
	 * The amount of found posts for the current query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   996
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   997
	 * If limit clause was not used, equals $post_count.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   998
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   999
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1000
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1001
	 * @var int
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1002
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1003
	public $found_posts = 0;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1004
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1005
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1006
	 * The amount of pages.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1007
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1008
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1009
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1010
	 * @var int
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1011
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1012
	public $max_num_pages = 0;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1013
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1014
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1015
	 * The amount of comment pages.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1016
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1017
	 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1018
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1019
	 * @var int
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1020
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1021
	public $max_num_comment_pages = 0;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1022
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1023
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1024
	 * Set if query is single post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1025
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1026
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1027
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1028
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1029
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1030
	public $is_single = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1031
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1032
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1033
	 * Set if query is preview of blog.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1034
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1035
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1036
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1037
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1038
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1039
	public $is_preview = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1040
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1041
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1042
	 * Set if query returns a page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1043
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1044
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1045
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1046
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1047
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1048
	public $is_page = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1049
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1050
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1051
	 * Set if query is an archive list.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1052
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1053
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1054
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1055
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1056
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1057
	public $is_archive = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1058
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1059
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1060
	 * Set if query is part of a date.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1061
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1062
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1063
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1064
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1065
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1066
	public $is_date = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1067
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1068
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1069
	 * Set if query contains a year.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1070
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1071
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1072
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1073
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1074
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1075
	public $is_year = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1076
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1077
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1078
	 * Set if query contains a month.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1079
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1080
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1081
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1082
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1083
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1084
	public $is_month = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1085
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1086
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1087
	 * Set if query contains a day.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1088
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1089
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1090
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1091
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1092
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1093
	public $is_day = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1094
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1095
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1096
	 * Set if query contains time.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1097
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1098
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1099
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1100
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1101
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1102
	public $is_time = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1103
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1104
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1105
	 * Set if query contains an author.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1106
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1107
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1108
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1109
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1110
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1111
	public $is_author = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1112
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1113
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1114
	 * Set if query contains category.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1115
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1116
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1117
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1118
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1119
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1120
	public $is_category = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1121
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1122
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1123
	 * Set if query contains tag.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1124
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1125
	 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1126
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1127
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1128
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1129
	public $is_tag = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1130
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1131
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1132
	 * Set if query contains taxonomy.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1133
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1134
	 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1135
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1136
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1137
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1138
	public $is_tax = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1139
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1140
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1141
	 * Set if query was part of a search result.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1142
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1143
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1144
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1145
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1146
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1147
	public $is_search = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1148
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1149
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1150
	 * Set if query is feed display.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1151
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1152
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1153
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1154
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1155
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1156
	public $is_feed = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1157
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1158
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1159
	 * Set if query is comment feed display.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1160
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1161
	 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1162
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1163
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1164
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1165
	public $is_comment_feed = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1166
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1167
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1168
	 * Set if query is trackback.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1169
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1170
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1171
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1172
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1173
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1174
	public $is_trackback = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1175
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1176
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1177
	 * Set if query is blog homepage.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1178
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1179
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1180
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1181
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1182
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1183
	public $is_home = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1184
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1185
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1186
	 * Set if query couldn't found anything.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1187
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1188
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1189
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1190
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1191
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1192
	public $is_404 = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1193
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1194
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1195
	 * Set if query is within comments popup window.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1196
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1197
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1198
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1199
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1200
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1201
	public $is_comments_popup = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1202
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1203
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1204
	 * Set if query is paged
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1205
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1206
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1207
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1208
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1209
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1210
	public $is_paged = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1211
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1212
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1213
	 * Set if query is part of administration page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1214
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1215
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1216
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1217
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1218
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1219
	public $is_admin = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1220
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1221
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1222
	 * Set if query is an attachment.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1223
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1224
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1225
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1226
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1227
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1228
	public $is_attachment = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1229
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1230
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1231
	 * Set if is single, is a page, or is an attachment.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1232
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1233
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1234
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1235
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1236
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1237
	public $is_singular = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1238
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1239
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1240
	 * Set if query is for robots.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1241
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1242
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1243
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1244
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1245
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1246
	public $is_robots = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1247
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1248
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1249
	 * Set if query contains posts.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1250
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1251
	 * Basically, the homepage if the option isn't set for the static homepage.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1252
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1253
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1254
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1255
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1256
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1257
	public $is_posts_page = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1258
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1259
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1260
	 * Set if query is for a post type archive.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1261
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1262
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1263
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1264
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1265
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1266
	public $is_post_type_archive = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1267
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1268
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1269
	 * Stores the ->query_vars state like md5(serialize( $this->query_vars ) ) so we know
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1270
	 * whether we have to re-parse because something has changed
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1271
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1272
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1273
	 * @access private
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1274
	 * @var bool|string
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1275
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1276
	private $query_vars_hash = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1277
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1278
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1279
	 * Whether query vars have changed since the initial parse_query() call. Used to catch modifications to query vars made
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1280
	 * via pre_get_posts hooks.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1281
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1282
	 * @since 3.1.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1283
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1284
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1285
	private $query_vars_changed = true;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1286
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1287
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1288
	 * Set if post thumbnails are cached
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1289
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1290
	 * @since 3.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1291
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1292
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1293
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1294
	 public $thumbnails_cached = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1295
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1296
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1297
	 * Cached list of search stopwords.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1298
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1299
	 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1300
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1301
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1302
	private $stopwords;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1303
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1304
	private $compat_fields = array( 'query_vars_hash', 'query_vars_changed' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1305
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1306
	private $compat_methods = array( 'init_query_flags', 'parse_tax_query' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1307
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1308
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1309
	 * Resets query flags to false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1310
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1311
	 * The query flags are what page info WordPress was able to figure out.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1312
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1313
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1314
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1315
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1316
	private function init_query_flags() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1317
		$this->is_single = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1318
		$this->is_preview = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1319
		$this->is_page = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1320
		$this->is_archive = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1321
		$this->is_date = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1322
		$this->is_year = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1323
		$this->is_month = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1324
		$this->is_day = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1325
		$this->is_time = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1326
		$this->is_author = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1327
		$this->is_category = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1328
		$this->is_tag = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1329
		$this->is_tax = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1330
		$this->is_search = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1331
		$this->is_feed = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1332
		$this->is_comment_feed = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1333
		$this->is_trackback = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1334
		$this->is_home = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1335
		$this->is_404 = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1336
		$this->is_comments_popup = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1337
		$this->is_paged = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1338
		$this->is_admin = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1339
		$this->is_attachment = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1340
		$this->is_singular = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1341
		$this->is_robots = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1342
		$this->is_posts_page = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1343
		$this->is_post_type_archive = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1344
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1345
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1346
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1347
	 * Initiates object properties and sets default values.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1348
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1349
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1350
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1351
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1352
	public function init() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1353
		unset($this->posts);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1354
		unset($this->query);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1355
		$this->query_vars = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1356
		unset($this->queried_object);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1357
		unset($this->queried_object_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1358
		$this->post_count = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1359
		$this->current_post = -1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1360
		$this->in_the_loop = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1361
		unset( $this->request );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1362
		unset( $this->post );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1363
		unset( $this->comments );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1364
		unset( $this->comment );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1365
		$this->comment_count = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1366
		$this->current_comment = -1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1367
		$this->found_posts = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1368
		$this->max_num_pages = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1369
		$this->max_num_comment_pages = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1370
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1371
		$this->init_query_flags();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1372
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1373
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1374
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1375
	 * Reparse the query vars.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1376
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1377
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1378
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1379
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1380
	public function parse_query_vars() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1381
		$this->parse_query();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1382
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1383
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1384
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1385
	 * Fills in the query variables, which do not exist within the parameter.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1386
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1387
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1388
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1389
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1390
	 * @param array $array Defined query variables.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1391
	 * @return array Complete query variables with undefined ones filled in empty.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1392
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1393
	public function fill_query_vars($array) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1394
		$keys = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1395
			'error'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1396
			, 'm'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1397
			, 'p'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1398
			, 'post_parent'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1399
			, 'subpost'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1400
			, 'subpost_id'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1401
			, 'attachment'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1402
			, 'attachment_id'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1403
			, 'name'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1404
			, 'static'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1405
			, 'pagename'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1406
			, 'page_id'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1407
			, 'second'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1408
			, 'minute'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1409
			, 'hour'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1410
			, 'day'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1411
			, 'monthnum'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1412
			, 'year'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1413
			, 'w'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1414
			, 'category_name'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1415
			, 'tag'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1416
			, 'cat'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1417
			, 'tag_id'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1418
			, 'author'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1419
			, 'author_name'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1420
			, 'feed'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1421
			, 'tb'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1422
			, 'paged'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1423
			, 'comments_popup'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1424
			, 'meta_key'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1425
			, 'meta_value'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1426
			, 'preview'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1427
			, 's'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1428
			, 'sentence'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1429
			, 'fields'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1430
			, 'menu_order'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1431
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1432
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1433
		foreach ( $keys as $key ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1434
			if ( !isset($array[$key]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1435
				$array[$key] = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1436
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1437
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1438
		$array_keys = array( 'category__in', 'category__not_in', 'category__and', 'post__in', 'post__not_in',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1439
			'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'post_parent__in', 'post_parent__not_in',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1440
			'author__in', 'author__not_in' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1441
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1442
		foreach ( $array_keys as $key ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1443
			if ( !isset($array[$key]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1444
				$array[$key] = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1445
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1446
		return $array;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1447
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1448
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1449
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1450
	 * Parse a query string and set query type booleans.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1451
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1452
	 * @since 1.5.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1453
	 * @since 4.2.0 Introduced the ability to order by specific clauses of a `$meta_query`, by passing the clause's
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1454
	 *              array key to `$orderby`.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1455
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1456
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1457
	 * @param string|array $query {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1458
	 *     Optional. Array or string of Query parameters.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1459
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1460
	 *     @type int          $attachment_id           Attachment post ID. Used for 'attachment' post_type.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1461
	 *     @type int|string   $author                  Author ID, or comma-separated list of IDs.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1462
	 *     @type string       $author_name             User 'user_nicename'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1463
	 *     @type array        $author__in              An array of author IDs to query from.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1464
	 *     @type array        $author__not_in          An array of author IDs not to query from.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1465
	 *     @type bool         $cache_results           Whether to cache post information. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1466
	 *     @type int|string   $cat                     Category ID or comma-separated list of IDs (this or any children).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1467
	 *     @type array        $category__and           An array of category IDs (AND in).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1468
	 *     @type array        $category__in            An array of category IDs (OR in, no children).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1469
	 *     @type array        $category__not_in        An array of category IDs (NOT in).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1470
	 *     @type string       $category_name           Use category slug (not name, this or any children).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1471
	 *     @type int          $comments_per_page       The number of comments to return per page.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1472
	 *                                                 Default 'comments_per_page' option.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1473
	 *     @type int|string   $comments_popup          Whether the query is within the comments popup. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1474
	 *     @type array        $date_query              An associative array of WP_Date_Query arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1475
	 *                                                 {@see WP_Date_Query::__construct()}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1476
	 *     @type int          $day                     Day of the month. Default empty. Accepts numbers 1-31.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1477
	 *     @type bool         $exact                   Whether to search by exact keyword. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1478
	 *     @type string|array $fields                  Which fields to return. Single field or all fields (string),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1479
	 *                                                 or array of fields. 'id=>parent' uses 'id' and 'post_parent'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1480
	 *                                                 Default all fields. Accepts 'ids', 'id=>parent'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1481
	 *     @type int          $hour                    Hour of the day. Default empty. Accepts numbers 0-23.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1482
	 *     @type int|bool     $ignore_sticky_posts     Whether to ignore sticky posts or not. Setting this to false
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1483
	 *                                                 excludes stickies from 'post__in'. Accepts 1|true, 0|false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1484
	 *                                                 Default 0|false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1485
	 *     @type int          $m                       Combination YearMonth. Accepts any four-digit year and month
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1486
	 *                                                 numbers 1-12. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1487
	 *     @type string       $meta_compare            Comparison operator to test the 'meta_value'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1488
	 *     @type string       $meta_key                Custom field key.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1489
	 *     @type array        $meta_query              An associative array of WP_Meta_Query arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1490
	 *                                                 {@see WP_Meta_Query->queries}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1491
	 *     @type string       $meta_value              Custom field value.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1492
	 *     @type int          $meta_value_num          Custom field value number.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1493
	 *     @type int          $menu_order              The menu order of the posts.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1494
	 *     @type int          $monthnum                The two-digit month. Default empty. Accepts numbers 1-12.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1495
	 *     @type string       $name                    Post slug.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1496
	 *     @type bool         $nopaging                Show all posts (true) or paginate (false). Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1497
	 *     @type bool         $no_found_rows           Whether to skip counting the total rows found. Enabling can improve
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1498
	 *                                                 performance. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1499
	 *     @type int          $offset                  The number of posts to offset before retrieval.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1500
	 *     @type string       $order                   Designates ascending or descending order of posts. Default 'DESC'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1501
	 *                                                 Accepts 'ASC', 'DESC'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1502
	 *     @type string|array $orderby                 Sort retrieved posts by parameter. One or more options may be
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1503
	 *                                                 passed. To use 'meta_value', or 'meta_value_num',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1504
	 *                                                 'meta_key=keyname' must be also be defined. To sort by a
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1505
	 *                                                 specific `$meta_query` clause, use that clause's array key.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1506
	 *                                                 Default 'date'. Accepts 'none', 'name', 'author', 'date',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1507
	 *                                                 'title', 'modified', 'menu_order', 'parent', 'ID', 'rand',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1508
	 *                                                 'comment_count', 'meta_value', 'meta_value_num', and the
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1509
	 *                                                 array keys of `$meta_query`.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1510
	 *     @type int          $p                       Post ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1511
	 *     @type int          $page                    Show the number of posts that would show up on page X of a
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1512
	 *                                                 static front page.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1513
	 *     @type int          $paged                   The number of the current page.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1514
	 *     @type int          $page_id                 Page ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1515
	 *     @type string       $pagename                Page slug.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1516
	 *     @type string       $perm                    Show posts if user has the appropriate capability.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1517
	 *     @type array        $post__in                An array of post IDs to retrieve, sticky posts will be included
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1518
	 *     @type string       $post_mime_type          The mime type of the post. Used for 'attachment' post_type.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1519
	 *     @type array        $post__not_in            An array of post IDs not to retrieve. Note: a string of comma-
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1520
	 *                                                 separated IDs will NOT work.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1521
	 *     @type int          $post_parent             Page ID to retrieve child pages for. Use 0 to only retrieve
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1522
	 *                                                 top-level pages.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1523
	 *     @type array        $post_parent__in         An array containing parent page IDs to query child pages from.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1524
	 *     @type array        $post_parent__not_in     An array containing parent page IDs not to query child pages from.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1525
	 *     @type string|array $post_type               A post type slug (string) or array of post type slugs.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1526
	 *                                                 Default 'any' if using 'tax_query'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1527
	 *     @type string|array $post_status             A post status (string) or array of post statuses.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1528
	 *     @type int          $posts_per_page          The number of posts to query for. Use -1 to request all posts.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1529
	 *     @type int          $posts_per_archive_page  The number of posts to query for by archive page. Overrides
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1530
	 *                                                 'posts_per_page' when is_archive(), or is_search() are true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1531
	 *     @type string       $s                       Search keyword.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1532
	 *     @type int          $second                  Second of the minute. Default empty. Accepts numbers 0-60.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1533
	 *     @type array        $search_terms            Array of search terms.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1534
	 *     @type bool         $sentence                Whether to search by phrase. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1535
	 *     @type bool         $suppress_filters        Whether to suppress filters. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1536
	 *     @type string       $tag                     Tag slug. Comma-separated (either), Plus-separated (all).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1537
	 *     @type array        $tag__and                An array of tag ids (AND in).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1538
	 *     @type array        $tag__in                 An array of tag ids (OR in).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1539
	 *     @type array        $tag__not_in             An array of tag ids (NOT in).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1540
	 *     @type int          $tag_id                  Tag id or comma-separated list of IDs.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1541
	 *     @type array        $tag_slug__and           An array of tag slugs (AND in).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1542
	 *     @type array        $tag_slug__in            An array of tag slugs (OR in). unless 'ignore_sticky_posts' is
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1543
	 *                                                 true. Note: a string of comma-separated IDs will NOT work.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1544
	 *     @type array        $tax_query               An associative array of WP_Tax_Query arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1545
	 *                                                 {@see WP_Tax_Query->queries}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1546
	 *     @type bool         $update_post_meta_cache  Whether to update the post meta cache. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1547
	 *     @type bool         $update_post_term_cache  Whether to update the post term cache. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1548
	 *     @type int          $w                       The week number of the year. Default empty. Accepts numbers 0-53.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1549
	 *     @type int          $year                    The four-digit year. Default empty. Accepts any four-digit year.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1550
	 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1551
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1552
	public function parse_query( $query =  '' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1553
		if ( ! empty( $query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1554
			$this->init();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1555
			$this->query = $this->query_vars = wp_parse_args( $query );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1556
		} elseif ( ! isset( $this->query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1557
			$this->query = $this->query_vars;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1558
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1559
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1560
		$this->query_vars = $this->fill_query_vars($this->query_vars);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1561
		$qv = &$this->query_vars;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1562
		$this->query_vars_changed = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1563
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1564
		if ( ! empty($qv['robots']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1565
			$this->is_robots = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1566
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1567
		$qv['p'] =  absint($qv['p']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1568
		$qv['page_id'] =  absint($qv['page_id']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1569
		$qv['year'] = absint($qv['year']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1570
		$qv['monthnum'] = absint($qv['monthnum']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1571
		$qv['day'] = absint($qv['day']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1572
		$qv['w'] = absint($qv['w']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1573
		$qv['m'] = preg_replace( '|[^0-9]|', '', $qv['m'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1574
		$qv['paged'] = absint($qv['paged']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1575
		$qv['cat'] = preg_replace( '|[^0-9,-]|', '', $qv['cat'] ); // comma separated list of positive or negative integers
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1576
		$qv['author'] = preg_replace( '|[^0-9,-]|', '', $qv['author'] ); // comma separated list of positive or negative integers
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1577
		$qv['pagename'] = trim( $qv['pagename'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1578
		$qv['name'] = trim( $qv['name'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1579
		if ( '' !== $qv['hour'] ) $qv['hour'] = absint($qv['hour']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1580
		if ( '' !== $qv['minute'] ) $qv['minute'] = absint($qv['minute']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1581
		if ( '' !== $qv['second'] ) $qv['second'] = absint($qv['second']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1582
		if ( '' !== $qv['menu_order'] ) $qv['menu_order'] = absint($qv['menu_order']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1583
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1584
		// Fairly insane upper bound for search string lengths.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1585
		if ( ! is_scalar( $qv['s'] ) || ( ! empty( $qv['s'] ) && strlen( $qv['s'] ) > 1600 ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1586
			$qv['s'] = '';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1587
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1588
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1589
		// Compat. Map subpost to attachment.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1590
		if ( '' != $qv['subpost'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1591
			$qv['attachment'] = $qv['subpost'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1592
		if ( '' != $qv['subpost_id'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1593
			$qv['attachment_id'] = $qv['subpost_id'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1594
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1595
		$qv['attachment_id'] = absint($qv['attachment_id']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1596
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1597
		if ( ('' != $qv['attachment']) || !empty($qv['attachment_id']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1598
			$this->is_single = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1599
			$this->is_attachment = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1600
		} elseif ( '' != $qv['name'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1601
			$this->is_single = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1602
		} elseif ( $qv['p'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1603
			$this->is_single = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1604
		} elseif ( ('' !== $qv['hour']) && ('' !== $qv['minute']) &&('' !== $qv['second']) && ('' != $qv['year']) && ('' != $qv['monthnum']) && ('' != $qv['day']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1605
			// If year, month, day, hour, minute, and second are set, a single
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1606
			// post is being queried.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1607
			$this->is_single = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1608
		} elseif ( '' != $qv['static'] || '' != $qv['pagename'] || !empty($qv['page_id']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1609
			$this->is_page = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1610
			$this->is_single = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1611
		} else {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1612
			// Look for archive queries. Dates, categories, authors, search, post type archives.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1613
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1614
			if ( isset( $this->query['s'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1615
				$this->is_search = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1616
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1617
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1618
			if ( '' !== $qv['second'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1619
				$this->is_time = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1620
				$this->is_date = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1621
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1622
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1623
			if ( '' !== $qv['minute'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1624
				$this->is_time = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1625
				$this->is_date = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1626
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1627
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1628
			if ( '' !== $qv['hour'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1629
				$this->is_time = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1630
				$this->is_date = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1631
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1632
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1633
			if ( $qv['day'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1634
				if ( ! $this->is_date ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1635
					$date = sprintf( '%04d-%02d-%02d', $qv['year'], $qv['monthnum'], $qv['day'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1636
					if ( $qv['monthnum'] && $qv['year'] && ! wp_checkdate( $qv['monthnum'], $qv['day'], $qv['year'], $date ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1637
						$qv['error'] = '404';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1638
					} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1639
						$this->is_day = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1640
						$this->is_date = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1641
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1642
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1643
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1644
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1645
			if ( $qv['monthnum'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1646
				if ( ! $this->is_date ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1647
					if ( 12 < $qv['monthnum'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1648
						$qv['error'] = '404';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1649
					} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1650
						$this->is_month = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1651
						$this->is_date = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1652
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1653
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1654
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1655
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1656
			if ( $qv['year'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1657
				if ( ! $this->is_date ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1658
					$this->is_year = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1659
					$this->is_date = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1660
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1661
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1662
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1663
			if ( $qv['m'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1664
				$this->is_date = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1665
				if ( strlen($qv['m']) > 9 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1666
					$this->is_time = true;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1667
				} elseif ( strlen( $qv['m'] ) > 7 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1668
					$this->is_day = true;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1669
				} elseif ( strlen( $qv['m'] ) > 5 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1670
					$this->is_month = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1671
				} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1672
					$this->is_year = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1673
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1674
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1675
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1676
			if ( '' != $qv['w'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1677
				$this->is_date = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1678
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1679
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1680
			$this->query_vars_hash = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1681
			$this->parse_tax_query( $qv );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1682
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1683
			foreach ( $this->tax_query->queries as $tax_query ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1684
				if ( ! is_array( $tax_query ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1685
					continue;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1686
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1687
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1688
				if ( isset( $tax_query['operator'] ) && 'NOT IN' != $tax_query['operator'] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1689
					switch ( $tax_query['taxonomy'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1690
						case 'category':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1691
							$this->is_category = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1692
							break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1693
						case 'post_tag':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1694
							$this->is_tag = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1695
							break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1696
						default:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1697
							$this->is_tax = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1698
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1699
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1700
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1701
			unset( $tax_query );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1702
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1703
			if ( empty($qv['author']) || ($qv['author'] == '0') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1704
				$this->is_author = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1705
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1706
				$this->is_author = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1707
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1708
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1709
			if ( '' != $qv['author_name'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1710
				$this->is_author = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1711
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1712
			if ( !empty( $qv['post_type'] ) && ! is_array( $qv['post_type'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1713
				$post_type_obj = get_post_type_object( $qv['post_type'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1714
				if ( ! empty( $post_type_obj->has_archive ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1715
					$this->is_post_type_archive = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1716
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1717
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1718
			if ( $this->is_post_type_archive || $this->is_date || $this->is_author || $this->is_category || $this->is_tag || $this->is_tax )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1719
				$this->is_archive = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1720
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1721
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1722
		if ( '' != $qv['feed'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1723
			$this->is_feed = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1724
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1725
		if ( '' != $qv['tb'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1726
			$this->is_trackback = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1727
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1728
		if ( '' != $qv['paged'] && ( intval($qv['paged']) > 1 ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1729
			$this->is_paged = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1730
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1731
		if ( '' != $qv['comments_popup'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1732
			$this->is_comments_popup = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1733
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1734
		// if we're previewing inside the write screen
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1735
		if ( '' != $qv['preview'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1736
			$this->is_preview = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1737
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1738
		if ( is_admin() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1739
			$this->is_admin = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1740
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1741
		if ( false !== strpos($qv['feed'], 'comments-') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1742
			$qv['feed'] = str_replace('comments-', '', $qv['feed']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1743
			$qv['withcomments'] = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1744
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1745
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1746
		$this->is_singular = $this->is_single || $this->is_page || $this->is_attachment;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1747
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1748
		if ( $this->is_feed && ( !empty($qv['withcomments']) || ( empty($qv['withoutcomments']) && $this->is_singular ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1749
			$this->is_comment_feed = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1750
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1751
		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_robots ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1752
			$this->is_home = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1753
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1754
		// Correct is_* for page_on_front and page_for_posts
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1755
		if ( $this->is_home && 'page' == get_option('show_on_front') && get_option('page_on_front') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1756
			$_query = wp_parse_args($this->query);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1757
			// pagename can be set and empty depending on matched rewrite rules. Ignore an empty pagename.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1758
			if ( isset($_query['pagename']) && '' == $_query['pagename'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1759
				unset($_query['pagename']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1760
			if ( empty($_query) || !array_diff( array_keys($_query), array('preview', 'page', 'paged', 'cpage') ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1761
				$this->is_page = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1762
				$this->is_home = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1763
				$qv['page_id'] = get_option('page_on_front');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1764
				// Correct <!--nextpage--> for page_on_front
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1765
				if ( !empty($qv['paged']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1766
					$qv['page'] = $qv['paged'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1767
					unset($qv['paged']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1768
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1769
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1770
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1771
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1772
		if ( '' != $qv['pagename'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1773
			$this->queried_object = get_page_by_path($qv['pagename']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1774
			if ( !empty($this->queried_object) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1775
				$this->queried_object_id = (int) $this->queried_object->ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1776
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1777
				unset($this->queried_object);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1778
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1779
			if  ( 'page' == get_option('show_on_front') && isset($this->queried_object_id) && $this->queried_object_id == get_option('page_for_posts') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1780
				$this->is_page = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1781
				$this->is_home = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1782
				$this->is_posts_page = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1783
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1784
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1785
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1786
		if ( $qv['page_id'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1787
			if  ( 'page' == get_option('show_on_front') && $qv['page_id'] == get_option('page_for_posts') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1788
				$this->is_page = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1789
				$this->is_home = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1790
				$this->is_posts_page = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1791
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1792
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1793
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1794
		if ( !empty($qv['post_type']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1795
			if ( is_array($qv['post_type']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1796
				$qv['post_type'] = array_map('sanitize_key', $qv['post_type']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1797
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1798
				$qv['post_type'] = sanitize_key($qv['post_type']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1799
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1800
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1801
		if ( ! empty( $qv['post_status'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1802
			if ( is_array( $qv['post_status'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1803
				$qv['post_status'] = array_map('sanitize_key', $qv['post_status']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1804
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1805
				$qv['post_status'] = preg_replace('|[^a-z0-9_,-]|', '', $qv['post_status']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1806
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1807
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1808
		if ( $this->is_posts_page && ( ! isset($qv['withcomments']) || ! $qv['withcomments'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1809
			$this->is_comment_feed = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1810
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1811
		$this->is_singular = $this->is_single || $this->is_page || $this->is_attachment;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1812
		// Done correcting is_* for page_on_front and page_for_posts
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1813
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1814
		if ( '404' == $qv['error'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1815
			$this->set_404();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1816
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1817
		$this->query_vars_hash = md5( serialize( $this->query_vars ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1818
		$this->query_vars_changed = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1819
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1820
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1821
		 * Fires after the main query vars have been parsed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1822
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1823
		 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1824
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1825
		 * @param WP_Query &$this The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1826
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1827
		do_action_ref_array( 'parse_query', array( &$this ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1828
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1829
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1830
	/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1831
	 * Parses various taxonomy related query vars.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1832
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1833
	 * For BC, this method is not marked as protected. See [28987].
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1834
	 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1835
	 * @access protected
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1836
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1837
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1838
	 * @param array &$q The query variables
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1839
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1840
	public function parse_tax_query( &$q ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1841
		if ( ! empty( $q['tax_query'] ) && is_array( $q['tax_query'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1842
			$tax_query = $q['tax_query'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1843
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1844
			$tax_query = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1845
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1846
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1847
		if ( !empty($q['taxonomy']) && !empty($q['term']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1848
			$tax_query[] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1849
				'taxonomy' => $q['taxonomy'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1850
				'terms' => array( $q['term'] ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1851
				'field' => 'slug',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1852
			);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1853
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1854
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1855
		foreach ( get_taxonomies( array() , 'objects' ) as $taxonomy => $t ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1856
			if ( 'post_tag' == $taxonomy )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1857
				continue;	// Handled further down in the $q['tag'] block
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1858
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1859
			if ( $t->query_var && !empty( $q[$t->query_var] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1860
				$tax_query_defaults = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1861
					'taxonomy' => $taxonomy,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1862
					'field' => 'slug',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1863
				);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1864
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1865
 				if ( isset( $t->rewrite['hierarchical'] ) && $t->rewrite['hierarchical'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1866
					$q[$t->query_var] = wp_basename( $q[$t->query_var] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1867
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1868
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1869
				$term = $q[$t->query_var];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1870
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1871
				if ( strpos($term, '+') !== false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1872
					$terms = preg_split( '/[+]+/', $term );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1873
					foreach ( $terms as $term ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1874
						$tax_query[] = array_merge( $tax_query_defaults, array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1875
							'terms' => array( $term )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1876
						) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1877
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1878
				} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1879
					$tax_query[] = array_merge( $tax_query_defaults, array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1880
						'terms' => preg_split( '/[,]+/', $term )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1881
					) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1882
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1883
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1884
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1885
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1886
		// Category stuff
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1887
		if ( ! empty( $q['cat'] ) && ! $this->is_singular ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1888
			$cat_in = $cat_not_in = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1889
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1890
			$cat_array = preg_split( '/[,\s]+/', urldecode( $q['cat'] ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1891
			$cat_array = array_map( 'intval', $cat_array );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1892
			$q['cat'] = implode( ',', $cat_array );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1893
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1894
			foreach ( $cat_array as $cat ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1895
				if ( $cat > 0 )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1896
					$cat_in[] = $cat;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1897
				elseif ( $cat < 0 )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1898
					$cat_not_in[] = abs( $cat );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1899
			}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1900
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1901
			if ( ! empty( $cat_in ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1902
				$tax_query[] = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1903
					'taxonomy' => 'category',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1904
					'terms' => $cat_in,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1905
					'field' => 'term_id',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1906
					'include_children' => true
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1907
				);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1908
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1909
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1910
			if ( ! empty( $cat_not_in ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1911
				$tax_query[] = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1912
					'taxonomy' => 'category',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1913
					'terms' => $cat_not_in,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1914
					'field' => 'term_id',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1915
					'operator' => 'NOT IN',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1916
					'include_children' => true
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1917
				);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1918
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1919
			unset( $cat_array, $cat_in, $cat_not_in );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1920
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1921
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1922
		if ( ! empty( $q['category__and'] ) && 1 === count( (array) $q['category__and'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1923
			$q['category__and'] = (array) $q['category__and'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1924
			if ( ! isset( $q['category__in'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1925
				$q['category__in'] = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1926
			$q['category__in'][] = absint( reset( $q['category__and'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1927
			unset( $q['category__and'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1928
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1929
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1930
		if ( ! empty( $q['category__in'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1931
			$q['category__in'] = array_map( 'absint', array_unique( (array) $q['category__in'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1932
			$tax_query[] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1933
				'taxonomy' => 'category',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1934
				'terms' => $q['category__in'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1935
				'field' => 'term_id',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1936
				'include_children' => false
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1937
			);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1938
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1939
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1940
		if ( ! empty($q['category__not_in']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1941
			$q['category__not_in'] = array_map( 'absint', array_unique( (array) $q['category__not_in'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1942
			$tax_query[] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1943
				'taxonomy' => 'category',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1944
				'terms' => $q['category__not_in'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1945
				'operator' => 'NOT IN',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1946
				'include_children' => false
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1947
			);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1948
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1949
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1950
		if ( ! empty($q['category__and']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1951
			$q['category__and'] = array_map( 'absint', array_unique( (array) $q['category__and'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1952
			$tax_query[] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1953
				'taxonomy' => 'category',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1954
				'terms' => $q['category__and'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1955
				'field' => 'term_id',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1956
				'operator' => 'AND',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1957
				'include_children' => false
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1958
			);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1959
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1960
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1961
		// Tag stuff
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1962
		if ( '' != $q['tag'] && !$this->is_singular && $this->query_vars_changed ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1963
			if ( strpos($q['tag'], ',') !== false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1964
				$tags = preg_split('/[,\r\n\t ]+/', $q['tag']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1965
				foreach ( (array) $tags as $tag ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1966
					$tag = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1967
					$q['tag_slug__in'][] = $tag;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1968
				}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1969
			} elseif ( preg_match('/[+\r\n\t ]+/', $q['tag'] ) || ! empty( $q['cat'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1970
				$tags = preg_split('/[+\r\n\t ]+/', $q['tag']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1971
				foreach ( (array) $tags as $tag ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1972
					$tag = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1973
					$q['tag_slug__and'][] = $tag;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1974
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1975
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1976
				$q['tag'] = sanitize_term_field('slug', $q['tag'], 0, 'post_tag', 'db');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1977
				$q['tag_slug__in'][] = $q['tag'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1978
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1979
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1980
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1981
		if ( !empty($q['tag_id']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1982
			$q['tag_id'] = absint( $q['tag_id'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1983
			$tax_query[] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1984
				'taxonomy' => 'post_tag',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1985
				'terms' => $q['tag_id']
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1986
			);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1987
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1988
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1989
		if ( !empty($q['tag__in']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1990
			$q['tag__in'] = array_map('absint', array_unique( (array) $q['tag__in'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1991
			$tax_query[] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1992
				'taxonomy' => 'post_tag',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1993
				'terms' => $q['tag__in']
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1994
			);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1995
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1996
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1997
		if ( !empty($q['tag__not_in']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1998
			$q['tag__not_in'] = array_map('absint', array_unique( (array) $q['tag__not_in'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1999
			$tax_query[] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2000
				'taxonomy' => 'post_tag',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2001
				'terms' => $q['tag__not_in'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2002
				'operator' => 'NOT IN'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2003
			);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2004
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2005
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2006
		if ( !empty($q['tag__and']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2007
			$q['tag__and'] = array_map('absint', array_unique( (array) $q['tag__and'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2008
			$tax_query[] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2009
				'taxonomy' => 'post_tag',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2010
				'terms' => $q['tag__and'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2011
				'operator' => 'AND'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2012
			);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2013
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2014
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2015
		if ( !empty($q['tag_slug__in']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2016
			$q['tag_slug__in'] = array_map('sanitize_title_for_query', array_unique( (array) $q['tag_slug__in'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2017
			$tax_query[] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2018
				'taxonomy' => 'post_tag',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2019
				'terms' => $q['tag_slug__in'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2020
				'field' => 'slug'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2021
			);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2022
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2023
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2024
		if ( !empty($q['tag_slug__and']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2025
			$q['tag_slug__and'] = array_map('sanitize_title_for_query', array_unique( (array) $q['tag_slug__and'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2026
			$tax_query[] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2027
				'taxonomy' => 'post_tag',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2028
				'terms' => $q['tag_slug__and'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2029
				'field' => 'slug',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2030
				'operator' => 'AND'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2031
			);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2032
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2033
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2034
		$this->tax_query = new WP_Tax_Query( $tax_query );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2035
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2036
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2037
		 * Fires after taxonomy-related query vars have been parsed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2038
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2039
		 * @since 3.7.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2040
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2041
		 * @param WP_Query $this The WP_Query instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2042
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2043
		do_action( 'parse_tax_query', $this );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2044
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2045
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2046
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2047
	 * Generate SQL for the WHERE clause based on passed search terms.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2048
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2049
	 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2050
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2051
	 * @global wpdb $wpdb
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2052
	 * @param array $q Query variables.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2053
	 * @return string WHERE clause.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2054
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2055
	protected function parse_search( &$q ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2056
		global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2057
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2058
		$search = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2059
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2060
		// added slashes screw with quote grouping when done early, so done later
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2061
		$q['s'] = stripslashes( $q['s'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2062
		if ( empty( $_GET['s'] ) && $this->is_main_query() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2063
			$q['s'] = urldecode( $q['s'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2064
		// there are no line breaks in <input /> fields
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2065
		$q['s'] = str_replace( array( "\r", "\n" ), '', $q['s'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2066
		$q['search_terms_count'] = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2067
		if ( ! empty( $q['sentence'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2068
			$q['search_terms'] = array( $q['s'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2069
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2070
			if ( preg_match_all( '/".*?("|$)|((?<=[\t ",+])|^)[^\t ",+]+/', $q['s'], $matches ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2071
				$q['search_terms_count'] = count( $matches[0] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2072
				$q['search_terms'] = $this->parse_search_terms( $matches[0] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2073
				// if the search string has only short terms or stopwords, or is 10+ terms long, match it as sentence
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2074
				if ( empty( $q['search_terms'] ) || count( $q['search_terms'] ) > 9 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2075
					$q['search_terms'] = array( $q['s'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2076
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2077
				$q['search_terms'] = array( $q['s'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2078
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2079
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2080
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2081
		$n = ! empty( $q['exact'] ) ? '' : '%';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2082
		$searchand = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2083
		$q['search_orderby_title'] = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2084
		foreach ( $q['search_terms'] as $term ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2085
			if ( $n ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2086
				$like = '%' . $wpdb->esc_like( $term ) . '%';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2087
				$q['search_orderby_title'][] = $wpdb->prepare( "$wpdb->posts.post_title LIKE %s", $like );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2088
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2089
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2090
			$like = $n . $wpdb->esc_like( $term ) . $n;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2091
			$search .= $wpdb->prepare( "{$searchand}(($wpdb->posts.post_title LIKE %s) OR ($wpdb->posts.post_content LIKE %s))", $like, $like );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2092
			$searchand = ' AND ';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2093
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2094
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2095
		if ( ! empty( $search ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2096
			$search = " AND ({$search}) ";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2097
			if ( ! is_user_logged_in() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2098
				$search .= " AND ($wpdb->posts.post_password = '') ";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2099
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2100
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2101
		return $search;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2102
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2103
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2104
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2105
	 * Check if the terms are suitable for searching.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2106
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2107
	 * Uses an array of stopwords (terms) that are excluded from the separate
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2108
	 * term matching when searching for posts. The list of English stopwords is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2109
	 * the approximate search engines list, and is translatable.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2110
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2111
	 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2112
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2113
	 * @param array $terms Terms to check.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2114
	 * @return array Terms that are not stopwords.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2115
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2116
	protected function parse_search_terms( $terms ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2117
		$strtolower = function_exists( 'mb_strtolower' ) ? 'mb_strtolower' : 'strtolower';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2118
		$checked = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2119
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2120
		$stopwords = $this->get_search_stopwords();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2121
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2122
		foreach ( $terms as $term ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2123
			// keep before/after spaces when term is for exact match
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2124
			if ( preg_match( '/^".+"$/', $term ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2125
				$term = trim( $term, "\"'" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2126
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2127
				$term = trim( $term, "\"' " );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2128
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2129
			// Avoid single A-Z.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2130
			if ( ! $term || ( 1 === strlen( $term ) && preg_match( '/^[a-z]$/i', $term ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2131
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2132
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2133
			if ( in_array( call_user_func( $strtolower, $term ), $stopwords, true ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2134
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2135
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2136
			$checked[] = $term;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2137
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2138
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2139
		return $checked;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2140
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2141
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2142
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2143
	 * Retrieve stopwords used when parsing search terms.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2144
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2145
	 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2146
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2147
	 * @return array Stopwords.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2148
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2149
	protected function get_search_stopwords() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2150
		if ( isset( $this->stopwords ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2151
			return $this->stopwords;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2152
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2153
		/* translators: This is a comma-separated list of very common words that should be excluded from a search,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2154
		 * like a, an, and the. These are usually called "stopwords". You should not simply translate these individual
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2155
		 * words into your language. Instead, look for and provide commonly accepted stopwords in your language.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2156
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2157
		$words = explode( ',', _x( 'about,an,are,as,at,be,by,com,for,from,how,in,is,it,of,on,or,that,the,this,to,was,what,when,where,who,will,with,www',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2158
			'Comma-separated list of search stopwords in your language' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2159
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2160
		$stopwords = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2161
		foreach( $words as $word ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2162
			$word = trim( $word, "\r\n\t " );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2163
			if ( $word )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2164
				$stopwords[] = $word;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2165
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2166
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2167
		/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2168
		 * Filter stopwords used when parsing search terms.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2169
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2170
		 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2171
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2172
		 * @param array $stopwords Stopwords.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2173
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2174
		$this->stopwords = apply_filters( 'wp_search_stopwords', $stopwords );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2175
		return $this->stopwords;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2176
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2177
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2178
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2179
	 * Generate SQL for the ORDER BY condition based on passed search terms.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2180
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2181
	 * @global wpdb $wpdb
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2182
	 * @param array $q Query variables.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2183
	 * @return string ORDER BY clause.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2184
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2185
	protected function parse_search_order( &$q ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2186
		global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2187
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2188
		if ( $q['search_terms_count'] > 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2189
			$num_terms = count( $q['search_orderby_title'] );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2190
			$like = '%' . $wpdb->esc_like( $q['s'] ) . '%';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2191
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2192
			$search_orderby = '(CASE ';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2193
			// sentence match in 'post_title'
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2194
			$search_orderby .= $wpdb->prepare( "WHEN $wpdb->posts.post_title LIKE %s THEN 1 ", $like );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2195
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2196
			// sanity limit, sort as sentence when more than 6 terms
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2197
			// (few searches are longer than 6 terms and most titles are not)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2198
			if ( $num_terms < 7 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2199
				// all words in title
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2200
				$search_orderby .= 'WHEN ' . implode( ' AND ', $q['search_orderby_title'] ) . ' THEN 2 ';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2201
				// any word in title, not needed when $num_terms == 1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2202
				if ( $num_terms > 1 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2203
					$search_orderby .= 'WHEN ' . implode( ' OR ', $q['search_orderby_title'] ) . ' THEN 3 ';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2204
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2205
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2206
			// sentence match in 'post_content'
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2207
			$search_orderby .= $wpdb->prepare( "WHEN $wpdb->posts.post_content LIKE %s THEN 4 ", $like );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2208
			$search_orderby .= 'ELSE 5 END)';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2209
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2210
			// single word or sentence search
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2211
			$search_orderby = reset( $q['search_orderby_title'] ) . ' DESC';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2212
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2213
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2214
		return $search_orderby;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2215
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2216
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2217
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2218
	 * If the passed orderby value is allowed, convert the alias to a
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2219
	 * properly-prefixed orderby value.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2220
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2221
	 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2222
	 * @access protected
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2223
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2224
	 * @global wpdb $wpdb WordPress database abstraction object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2225
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2226
	 * @param string $orderby Alias for the field to order by.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2227
	 * @return string|bool Table-prefixed value to used in the ORDER clause. False otherwise.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2228
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2229
	protected function parse_orderby( $orderby ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2230
		global $wpdb;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2231
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2232
		// Used to filter values.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2233
		$allowed_keys = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2234
			'post_name', 'post_author', 'post_date', 'post_title', 'post_modified',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2235
			'post_parent', 'post_type', 'name', 'author', 'date', 'title', 'modified',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2236
			'parent', 'type', 'ID', 'menu_order', 'comment_count', 'rand',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2237
		);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2238
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2239
		$primary_meta_key = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2240
		$primary_meta_query = false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2241
		$meta_clauses = $this->meta_query->get_clauses();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2242
		if ( ! empty( $meta_clauses ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2243
			$primary_meta_query = reset( $meta_clauses );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2244
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2245
			if ( ! empty( $primary_meta_query['key'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2246
				$primary_meta_key = $primary_meta_query['key'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2247
				$allowed_keys[] = $primary_meta_key;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2248
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2249
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2250
			$allowed_keys[] = 'meta_value';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2251
			$allowed_keys[] = 'meta_value_num';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2252
			$allowed_keys   = array_merge( $allowed_keys, array_keys( $meta_clauses ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2253
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2254
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2255
		if ( ! in_array( $orderby, $allowed_keys ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2256
			return false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2257
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2258
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2259
		switch ( $orderby ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2260
			case 'post_name':
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2261
			case 'post_author':
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2262
			case 'post_date':
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2263
			case 'post_title':
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2264
			case 'post_modified':
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2265
			case 'post_parent':
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2266
			case 'post_type':
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2267
			case 'ID':
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2268
			case 'menu_order':
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2269
			case 'comment_count':
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2270
				$orderby_clause = "$wpdb->posts.{$orderby}";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2271
				break;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2272
			case 'rand':
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2273
				$orderby_clause = 'RAND()';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2274
				break;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2275
			case $primary_meta_key:
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2276
			case 'meta_value':
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2277
				if ( ! empty( $primary_meta_query['type'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2278
					$orderby_clause = "CAST({$primary_meta_query['alias']}.meta_value AS {$primary_meta_query['cast']})";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2279
				} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2280
					$orderby_clause = "{$primary_meta_query['alias']}.meta_value";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2281
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2282
				break;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2283
			case 'meta_value_num':
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2284
				$orderby_clause = "{$primary_meta_query['alias']}.meta_value+0";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2285
				break;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2286
			default:
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2287
				if ( array_key_exists( $orderby, $meta_clauses ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2288
					// $orderby corresponds to a meta_query clause.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2289
					$meta_clause = $meta_clauses[ $orderby ];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2290
					$orderby_clause = "CAST({$meta_clause['alias']}.meta_value AS {$meta_clause['cast']})";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2291
				} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2292
					// Default: order by post field.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2293
					$orderby_clause = "$wpdb->posts.post_" . sanitize_key( $orderby );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2294
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2295
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2296
				break;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2297
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2298
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2299
		return $orderby_clause;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2300
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2301
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2302
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2303
	 * Parse an 'order' query variable and cast it to ASC or DESC as necessary.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2304
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2305
	 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2306
	 * @access protected
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2307
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2308
	 * @param string $order The 'order' query variable.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2309
	 * @return string The sanitized 'order' query variable.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2310
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2311
	protected function parse_order( $order ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2312
		if ( ! is_string( $order ) || empty( $order ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2313
			return 'DESC';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2314
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2315
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2316
		if ( 'ASC' === strtoupper( $order ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2317
			return 'ASC';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2318
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2319
			return 'DESC';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2320
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2321
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2322
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2323
	/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2324
	 * Sets the 404 property and saves whether query is feed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2325
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2326
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2327
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2328
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2329
	public function set_404() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2330
		$is_feed = $this->is_feed;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2331
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2332
		$this->init_query_flags();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2333
		$this->is_404 = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2334
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2335
		$this->is_feed = $is_feed;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2336
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2337
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2338
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2339
	 * Retrieve query variable.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2340
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2341
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2342
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2343
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2344
	 * @param string $query_var Query variable key.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2345
	 * @param mixed  $default   Value to return if the query variable is not set. Default ''.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2346
	 * @return mixed
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2347
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2348
	public function get( $query_var, $default = '' ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2349
		if ( isset( $this->query_vars[ $query_var ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2350
			return $this->query_vars[ $query_var ];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2351
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2352
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2353
		return $default;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2354
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2355
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2356
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2357
	 * Set query variable.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2358
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2359
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2360
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2361
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2362
	 * @param string $query_var Query variable key.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2363
	 * @param mixed $value Query variable value.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2364
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2365
	public function set($query_var, $value) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2366
		$this->query_vars[$query_var] = $value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2367
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2368
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2369
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2370
	 * Retrieve the posts based on query variables.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2371
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2372
	 * There are a few filters and actions that can be used to modify the post
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2373
	 * database query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2374
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2375
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2376
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2377
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2378
	 * @return array List of posts.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2379
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2380
	public function get_posts() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2381
		global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2382
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2383
		$this->parse_query();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2384
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2385
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2386
		 * Fires after the query variable object is created, but before the actual query is run.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2387
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2388
		 * Note: If using conditional tags, use the method versions within the passed instance
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2389
		 * (e.g. $this->is_main_query() instead of is_main_query()). This is because the functions
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2390
		 * like is_main_query() test against the global $wp_query instance, not the passed one.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2391
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2392
		 * @since 2.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2393
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2394
		 * @param WP_Query &$this The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2395
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2396
		do_action_ref_array( 'pre_get_posts', array( &$this ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2397
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2398
		// Shorthand.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2399
		$q = &$this->query_vars;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2400
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2401
		// Fill again in case pre_get_posts unset some vars.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2402
		$q = $this->fill_query_vars($q);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2403
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2404
		// Parse meta query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2405
		$this->meta_query = new WP_Meta_Query();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2406
		$this->meta_query->parse_query_vars( $q );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2407
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2408
		// Set a flag if a pre_get_posts hook changed the query vars.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2409
		$hash = md5( serialize( $this->query_vars ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2410
		if ( $hash != $this->query_vars_hash ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2411
			$this->query_vars_changed = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2412
			$this->query_vars_hash = $hash;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2413
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2414
		unset($hash);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2415
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2416
		// First let's clear some variables
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2417
		$distinct = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2418
		$whichauthor = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2419
		$whichmimetype = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2420
		$where = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2421
		$limits = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2422
		$join = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2423
		$search = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2424
		$groupby = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2425
		$post_status_join = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2426
		$page = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2427
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2428
		if ( isset( $q['caller_get_posts'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2429
			_deprecated_argument( 'WP_Query', '3.1', __( '"caller_get_posts" is deprecated. Use "ignore_sticky_posts" instead.' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2430
			if ( !isset( $q['ignore_sticky_posts'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2431
				$q['ignore_sticky_posts'] = $q['caller_get_posts'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2432
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2433
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2434
		if ( !isset( $q['ignore_sticky_posts'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2435
			$q['ignore_sticky_posts'] = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2436
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2437
		if ( !isset($q['suppress_filters']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2438
			$q['suppress_filters'] = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2439
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2440
		if ( !isset($q['cache_results']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2441
			if ( wp_using_ext_object_cache() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2442
				$q['cache_results'] = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2443
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2444
				$q['cache_results'] = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2445
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2446
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2447
		if ( !isset($q['update_post_term_cache']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2448
			$q['update_post_term_cache'] = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2449
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2450
		if ( !isset($q['update_post_meta_cache']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2451
			$q['update_post_meta_cache'] = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2452
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2453
		if ( !isset($q['post_type']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2454
			if ( $this->is_search )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2455
				$q['post_type'] = 'any';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2456
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2457
				$q['post_type'] = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2458
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2459
		$post_type = $q['post_type'];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2460
		if ( empty( $q['posts_per_page'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2461
			$q['posts_per_page'] = get_option( 'posts_per_page' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2462
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2463
		if ( isset($q['showposts']) && $q['showposts'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2464
			$q['showposts'] = (int) $q['showposts'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2465
			$q['posts_per_page'] = $q['showposts'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2466
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2467
		if ( (isset($q['posts_per_archive_page']) && $q['posts_per_archive_page'] != 0) && ($this->is_archive || $this->is_search) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2468
			$q['posts_per_page'] = $q['posts_per_archive_page'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2469
		if ( !isset($q['nopaging']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2470
			if ( $q['posts_per_page'] == -1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2471
				$q['nopaging'] = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2472
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2473
				$q['nopaging'] = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2474
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2475
		}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2476
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2477
		if ( $this->is_feed ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2478
			// This overrides posts_per_page.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2479
			if ( ! empty( $q['posts_per_rss'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2480
				$q['posts_per_page'] = $q['posts_per_rss'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2481
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2482
				$q['posts_per_page'] = get_option( 'posts_per_rss' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2483
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2484
			$q['nopaging'] = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2485
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2486
		$q['posts_per_page'] = (int) $q['posts_per_page'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2487
		if ( $q['posts_per_page'] < -1 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2488
			$q['posts_per_page'] = abs($q['posts_per_page']);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2489
		elseif ( $q['posts_per_page'] == 0 )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2490
			$q['posts_per_page'] = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2491
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2492
		if ( !isset($q['comments_per_page']) || $q['comments_per_page'] == 0 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2493
			$q['comments_per_page'] = get_option('comments_per_page');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2494
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2495
		if ( $this->is_home && (empty($this->query) || $q['preview'] == 'true') && ( 'page' == get_option('show_on_front') ) && get_option('page_on_front') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2496
			$this->is_page = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2497
			$this->is_home = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2498
			$q['page_id'] = get_option('page_on_front');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2499
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2500
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2501
		if ( isset($q['page']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2502
			$q['page'] = trim($q['page'], '/');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2503
			$q['page'] = absint($q['page']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2504
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2505
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2506
		// If true, forcibly turns off SQL_CALC_FOUND_ROWS even when limits are present.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2507
		if ( isset($q['no_found_rows']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2508
			$q['no_found_rows'] = (bool) $q['no_found_rows'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2509
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2510
			$q['no_found_rows'] = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2511
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2512
		switch ( $q['fields'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2513
			case 'ids':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2514
				$fields = "$wpdb->posts.ID";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2515
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2516
			case 'id=>parent':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2517
				$fields = "$wpdb->posts.ID, $wpdb->posts.post_parent";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2518
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2519
			default:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2520
				$fields = "$wpdb->posts.*";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2521
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2522
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2523
		if ( '' !== $q['menu_order'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2524
			$where .= " AND $wpdb->posts.menu_order = " . $q['menu_order'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2525
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2526
		// The "m" parameter is meant for months but accepts datetimes of varying specificity
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2527
		if ( $q['m'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2528
			$where .= " AND YEAR($wpdb->posts.post_date)=" . substr($q['m'], 0, 4);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2529
			if ( strlen($q['m']) > 5 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2530
				$where .= " AND MONTH($wpdb->posts.post_date)=" . substr($q['m'], 4, 2);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2531
			if ( strlen($q['m']) > 7 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2532
				$where .= " AND DAYOFMONTH($wpdb->posts.post_date)=" . substr($q['m'], 6, 2);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2533
			if ( strlen($q['m']) > 9 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2534
				$where .= " AND HOUR($wpdb->posts.post_date)=" . substr($q['m'], 8, 2);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2535
			if ( strlen($q['m']) > 11 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2536
				$where .= " AND MINUTE($wpdb->posts.post_date)=" . substr($q['m'], 10, 2);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2537
			if ( strlen($q['m']) > 13 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2538
				$where .= " AND SECOND($wpdb->posts.post_date)=" . substr($q['m'], 12, 2);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2539
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2540
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2541
		// Handle the other individual date parameters
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2542
		$date_parameters = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2543
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2544
		if ( '' !== $q['hour'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2545
			$date_parameters['hour'] = $q['hour'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2546
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2547
		if ( '' !== $q['minute'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2548
			$date_parameters['minute'] = $q['minute'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2549
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2550
		if ( '' !== $q['second'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2551
			$date_parameters['second'] = $q['second'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2552
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2553
		if ( $q['year'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2554
			$date_parameters['year'] = $q['year'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2555
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2556
		if ( $q['monthnum'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2557
			$date_parameters['monthnum'] = $q['monthnum'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2558
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2559
		if ( $q['w'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2560
			$date_parameters['week'] = $q['w'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2561
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2562
		if ( $q['day'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2563
			$date_parameters['day'] = $q['day'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2564
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2565
		if ( $date_parameters ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2566
			$date_query = new WP_Date_Query( array( $date_parameters ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2567
			$where .= $date_query->get_sql();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2568
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2569
		unset( $date_parameters, $date_query );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2570
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2571
		// Handle complex date queries
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2572
		if ( ! empty( $q['date_query'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2573
			$this->date_query = new WP_Date_Query( $q['date_query'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2574
			$where .= $this->date_query->get_sql();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2575
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2576
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2577
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2578
		// If we've got a post_type AND it's not "any" post_type.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2579
		if ( !empty($q['post_type']) && 'any' != $q['post_type'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2580
			foreach ( (array)$q['post_type'] as $_post_type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2581
				$ptype_obj = get_post_type_object($_post_type);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2582
				if ( !$ptype_obj || !$ptype_obj->query_var || empty($q[ $ptype_obj->query_var ]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2583
					continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2584
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2585
				if ( ! $ptype_obj->hierarchical ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2586
					// Non-hierarchical post types can directly use 'name'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2587
					$q['name'] = $q[ $ptype_obj->query_var ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2588
				} else {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2589
					// Hierarchical post types will operate through 'pagename'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2590
					$q['pagename'] = $q[ $ptype_obj->query_var ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2591
					$q['name'] = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2592
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2593
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2594
				// Only one request for a slug is possible, this is why name & pagename are overwritten above.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2595
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2596
			} //end foreach
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2597
			unset($ptype_obj);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2598
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2599
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2600
		if ( '' != $q['name'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2601
			$q['name'] = sanitize_title_for_query( $q['name'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2602
			$where .= " AND $wpdb->posts.post_name = '" . $q['name'] . "'";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2603
		} elseif ( '' != $q['pagename'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2604
			if ( isset($this->queried_object_id) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2605
				$reqpage = $this->queried_object_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2606
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2607
				if ( 'page' != $q['post_type'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2608
					foreach ( (array)$q['post_type'] as $_post_type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2609
						$ptype_obj = get_post_type_object($_post_type);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2610
						if ( !$ptype_obj || !$ptype_obj->hierarchical )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2611
							continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2612
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2613
						$reqpage = get_page_by_path($q['pagename'], OBJECT, $_post_type);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2614
						if ( $reqpage )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2615
							break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2616
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2617
					unset($ptype_obj);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2618
				} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2619
					$reqpage = get_page_by_path($q['pagename']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2620
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2621
				if ( !empty($reqpage) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2622
					$reqpage = $reqpage->ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2623
				else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2624
					$reqpage = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2625
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2626
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2627
			$page_for_posts = get_option('page_for_posts');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2628
			if  ( ('page' != get_option('show_on_front') ) || empty($page_for_posts) || ( $reqpage != $page_for_posts ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2629
				$q['pagename'] = sanitize_title_for_query( wp_basename( $q['pagename'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2630
				$q['name'] = $q['pagename'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2631
				$where .= " AND ($wpdb->posts.ID = '$reqpage')";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2632
				$reqpage_obj = get_post( $reqpage );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2633
				if ( is_object($reqpage_obj) && 'attachment' == $reqpage_obj->post_type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2634
					$this->is_attachment = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2635
					$post_type = $q['post_type'] = 'attachment';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2636
					$this->is_page = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2637
					$q['attachment_id'] = $reqpage;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2638
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2639
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2640
		} elseif ( '' != $q['attachment'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2641
			$q['attachment'] = sanitize_title_for_query( wp_basename( $q['attachment'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2642
			$q['name'] = $q['attachment'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2643
			$where .= " AND $wpdb->posts.post_name = '" . $q['attachment'] . "'";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2644
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2645
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2646
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2647
		if ( intval($q['comments_popup']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2648
			$q['p'] = absint($q['comments_popup']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2649
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2650
		// If an attachment is requested by number, let it supersede any post number.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2651
		if ( $q['attachment_id'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2652
			$q['p'] = absint($q['attachment_id']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2653
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2654
		// If a post number is specified, load that post
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2655
		if ( $q['p'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2656
			$where .= " AND {$wpdb->posts}.ID = " . $q['p'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2657
		} elseif ( $q['post__in'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2658
			$post__in = implode(',', array_map( 'absint', $q['post__in'] ));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2659
			$where .= " AND {$wpdb->posts}.ID IN ($post__in)";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2660
		} elseif ( $q['post__not_in'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2661
			$post__not_in = implode(',',  array_map( 'absint', $q['post__not_in'] ));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2662
			$where .= " AND {$wpdb->posts}.ID NOT IN ($post__not_in)";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2663
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2664
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2665
		if ( is_numeric( $q['post_parent'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2666
			$where .= $wpdb->prepare( " AND $wpdb->posts.post_parent = %d ", $q['post_parent'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2667
		} elseif ( $q['post_parent__in'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2668
			$post_parent__in = implode( ',', array_map( 'absint', $q['post_parent__in'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2669
			$where .= " AND {$wpdb->posts}.post_parent IN ($post_parent__in)";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2670
		} elseif ( $q['post_parent__not_in'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2671
			$post_parent__not_in = implode( ',',  array_map( 'absint', $q['post_parent__not_in'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2672
			$where .= " AND {$wpdb->posts}.post_parent NOT IN ($post_parent__not_in)";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2673
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2674
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2675
		if ( $q['page_id'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2676
			if  ( ('page' != get_option('show_on_front') ) || ( $q['page_id'] != get_option('page_for_posts') ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2677
				$q['p'] = $q['page_id'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2678
				$where = " AND {$wpdb->posts}.ID = " . $q['page_id'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2679
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2680
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2681
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2682
		// If a search pattern is specified, load the posts that match.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2683
		if ( ! empty( $q['s'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2684
			$search = $this->parse_search( $q );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2685
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2686
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2687
		/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2688
		 * Filter the search SQL that is used in the WHERE clause of WP_Query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2689
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2690
		 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2691
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2692
		 * @param string   $search Search SQL for WHERE clause.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2693
		 * @param WP_Query $this   The current WP_Query object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2694
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2695
		$search = apply_filters_ref_array( 'posts_search', array( $search, &$this ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2696
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2697
		// Taxonomies
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2698
		if ( !$this->is_singular ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2699
			$this->parse_tax_query( $q );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2700
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2701
			$clauses = $this->tax_query->get_sql( $wpdb->posts, 'ID' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2702
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2703
			$join .= $clauses['join'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2704
			$where .= $clauses['where'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2705
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2706
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2707
		if ( $this->is_tax ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2708
			if ( empty($post_type) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2709
				// Do a fully inclusive search for currently registered post types of queried taxonomies
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2710
				$post_type = array();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2711
				$taxonomies = array_keys( $this->tax_query->queried_terms );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2712
				foreach ( get_post_types( array( 'exclude_from_search' => false ) ) as $pt ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2713
					$object_taxonomies = $pt === 'attachment' ? get_taxonomies_for_attachments() : get_object_taxonomies( $pt );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2714
					if ( array_intersect( $taxonomies, $object_taxonomies ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2715
						$post_type[] = $pt;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2716
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2717
				if ( ! $post_type )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2718
					$post_type = 'any';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2719
				elseif ( count( $post_type ) == 1 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2720
					$post_type = $post_type[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2721
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2722
				$post_status_join = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2723
			} elseif ( in_array('attachment', (array) $post_type) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2724
				$post_status_join = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2725
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2726
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2727
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2728
		/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2729
		 * Ensure that 'taxonomy', 'term', 'term_id', 'cat', and
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2730
		 * 'category_name' vars are set for backward compatibility.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2731
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2732
		if ( ! empty( $this->tax_query->queried_terms ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2733
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2734
			/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2735
			 * Set 'taxonomy', 'term', and 'term_id' to the
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2736
			 * first taxonomy other than 'post_tag' or 'category'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2737
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2738
			if ( ! isset( $q['taxonomy'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2739
				foreach ( $this->tax_query->queried_terms as $queried_taxonomy => $queried_items ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2740
					if ( empty( $queried_items['terms'][0] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2741
						continue;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2742
					}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2743
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2744
					if ( ! in_array( $queried_taxonomy, array( 'category', 'post_tag' ) ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2745
						$q['taxonomy'] = $queried_taxonomy;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2746
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2747
						if ( 'slug' === $queried_items['field'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2748
							$q['term'] = $queried_items['terms'][0];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2749
						} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2750
							$q['term_id'] = $queried_items['terms'][0];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2751
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2752
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2753
				}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2754
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2755
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2756
			// 'cat', 'category_name', 'tag_id'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2757
			foreach ( $this->tax_query->queried_terms as $queried_taxonomy => $queried_items ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2758
				if ( empty( $queried_items['terms'][0] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2759
					continue;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2760
				}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2761
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2762
				if ( 'category' === $queried_taxonomy ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2763
					$the_cat = get_term_by( $queried_items['field'], $queried_items['terms'][0], 'category' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2764
					if ( $the_cat ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2765
						$this->set( 'cat', $the_cat->term_id );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2766
						$this->set( 'category_name', $the_cat->slug );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2767
					}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2768
					unset( $the_cat );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2769
				}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2770
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2771
				if ( 'post_tag' === $queried_taxonomy ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2772
					$the_tag = get_term_by( $queried_items['field'], $queried_items['terms'][0], 'post_tag' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2773
					if ( $the_tag ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2774
						$this->set( 'tag_id', $the_tag->term_id );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2775
					}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2776
					unset( $the_tag );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2777
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2778
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2779
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2780
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2781
		if ( !empty( $this->tax_query->queries ) || !empty( $this->meta_query->queries ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2782
			$groupby = "{$wpdb->posts}.ID";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2783
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2784
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2785
		// Author/user stuff
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2786
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2787
		if ( ! empty( $q['author'] ) && $q['author'] != '0' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2788
			$q['author'] = addslashes_gpc( '' . urldecode( $q['author'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2789
			$authors = array_unique( array_map( 'intval', preg_split( '/[,\s]+/', $q['author'] ) ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2790
			foreach ( $authors as $author ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2791
				$key = $author > 0 ? 'author__in' : 'author__not_in';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2792
				$q[$key][] = abs( $author );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2793
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2794
			$q['author'] = implode( ',', $authors );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2795
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2796
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2797
		if ( ! empty( $q['author__not_in'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2798
			$author__not_in = implode( ',', array_map( 'absint', array_unique( (array) $q['author__not_in'] ) ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2799
			$where .= " AND {$wpdb->posts}.post_author NOT IN ($author__not_in) ";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2800
		} elseif ( ! empty( $q['author__in'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2801
			$author__in = implode( ',', array_map( 'absint', array_unique( (array) $q['author__in'] ) ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2802
			$where .= " AND {$wpdb->posts}.post_author IN ($author__in) ";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2803
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2804
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2805
		// Author stuff for nice URLs
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2806
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2807
		if ( '' != $q['author_name'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2808
			if ( strpos($q['author_name'], '/') !== false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2809
				$q['author_name'] = explode('/', $q['author_name']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2810
				if ( $q['author_name'][ count($q['author_name'])-1 ] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2811
					$q['author_name'] = $q['author_name'][count($q['author_name'])-1]; // no trailing slash
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2812
				} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2813
					$q['author_name'] = $q['author_name'][count($q['author_name'])-2]; // there was a trailing slash
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2814
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2815
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2816
			$q['author_name'] = sanitize_title_for_query( $q['author_name'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2817
			$q['author'] = get_user_by('slug', $q['author_name']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2818
			if ( $q['author'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2819
				$q['author'] = $q['author']->ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2820
			$whichauthor .= " AND ($wpdb->posts.post_author = " . absint($q['author']) . ')';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2821
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2822
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2823
		// MIME-Type stuff for attachment browsing
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2824
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2825
		if ( isset( $q['post_mime_type'] ) && '' != $q['post_mime_type'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2826
			$whichmimetype = wp_post_mime_type_where( $q['post_mime_type'], $wpdb->posts );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2827
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2828
		$where .= $search . $whichauthor . $whichmimetype;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2829
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2830
		if ( ! empty( $this->meta_query->queries ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2831
			$clauses = $this->meta_query->get_sql( 'post', $wpdb->posts, 'ID', $this );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2832
			$join   .= $clauses['join'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2833
			$where  .= $clauses['where'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2834
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2835
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2836
		$rand = ( isset( $q['orderby'] ) && 'rand' === $q['orderby'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2837
		if ( ! isset( $q['order'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2838
			$q['order'] = $rand ? '' : 'DESC';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2839
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2840
			$q['order'] = $rand ? '' : $this->parse_order( $q['order'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2841
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2842
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2843
		// Order by.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2844
		if ( empty( $q['orderby'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2845
			/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2846
			 * Boolean false or empty array blanks out ORDER BY,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2847
			 * while leaving the value unset or otherwise empty sets the default.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2848
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2849
			if ( isset( $q['orderby'] ) && ( is_array( $q['orderby'] ) || false === $q['orderby'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2850
				$orderby = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2851
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2852
				$orderby = "$wpdb->posts.post_date " . $q['order'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2853
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2854
		} elseif ( 'none' == $q['orderby'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2855
			$orderby = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2856
		} elseif ( $q['orderby'] == 'post__in' && ! empty( $post__in ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2857
			$orderby = "FIELD( {$wpdb->posts}.ID, $post__in )";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2858
		} elseif ( $q['orderby'] == 'post_parent__in' && ! empty( $post_parent__in ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2859
			$orderby = "FIELD( {$wpdb->posts}.post_parent, $post_parent__in )";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2860
		} else {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2861
			$orderby_array = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2862
			if ( is_array( $q['orderby'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2863
				foreach ( $q['orderby'] as $_orderby => $order ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2864
					$orderby = addslashes_gpc( urldecode( $_orderby ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2865
					$parsed  = $this->parse_orderby( $orderby );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2866
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2867
					if ( ! $parsed ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2868
						continue;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2869
					}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2870
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2871
					$orderby_array[] = $parsed . ' ' . $this->parse_order( $order );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2872
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2873
				$orderby = implode( ', ', $orderby_array );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2874
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2875
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2876
				$q['orderby'] = urldecode( $q['orderby'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2877
				$q['orderby'] = addslashes_gpc( $q['orderby'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2878
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2879
				foreach ( explode( ' ', $q['orderby'] ) as $i => $orderby ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2880
					$parsed = $this->parse_orderby( $orderby );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2881
					// Only allow certain values for safety.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2882
					if ( ! $parsed ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2883
						continue;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2884
					}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2885
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2886
					$orderby_array[] = $parsed;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2887
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2888
				$orderby = implode( ' ' . $q['order'] . ', ', $orderby_array );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2889
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2890
				if ( empty( $orderby ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2891
					$orderby = "$wpdb->posts.post_date " . $q['order'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2892
				} elseif ( ! empty( $q['order'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2893
					$orderby .= " {$q['order']}";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2894
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2895
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2896
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2897
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2898
		// Order search results by relevance only when another "orderby" is not specified in the query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2899
		if ( ! empty( $q['s'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2900
			$search_orderby = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2901
			if ( ! empty( $q['search_orderby_title'] ) && ( empty( $q['orderby'] ) && ! $this->is_feed ) || ( isset( $q['orderby'] ) && 'relevance' === $q['orderby'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2902
				$search_orderby = $this->parse_search_order( $q );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2903
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2904
			/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2905
			 * Filter the ORDER BY used when ordering search results.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2906
			 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2907
			 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2908
			 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2909
			 * @param string   $search_orderby The ORDER BY clause.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2910
			 * @param WP_Query $this           The current WP_Query instance.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2911
			 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2912
			$search_orderby = apply_filters( 'posts_search_orderby', $search_orderby, $this );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2913
			if ( $search_orderby )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2914
				$orderby = $orderby ? $search_orderby . ', ' . $orderby : $search_orderby;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2915
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2916
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2917
		if ( is_array( $post_type ) && count( $post_type ) > 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2918
			$post_type_cap = 'multiple_post_type';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2919
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2920
			if ( is_array( $post_type ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2921
				$post_type = reset( $post_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2922
			$post_type_object = get_post_type_object( $post_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2923
			if ( empty( $post_type_object ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2924
				$post_type_cap = $post_type;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2925
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2926
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2927
		if ( isset( $q['post_password'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2928
			$where .= $wpdb->prepare( " AND $wpdb->posts.post_password = %s", $q['post_password'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2929
			if ( empty( $q['perm'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2930
				$q['perm'] = 'readable';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2931
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2932
		} elseif ( isset( $q['has_password'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2933
			$where .= sprintf( " AND $wpdb->posts.post_password %s ''", $q['has_password'] ? '!=' : '=' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2934
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2935
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2936
		if ( 'any' == $post_type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2937
			$in_search_post_types = get_post_types( array('exclude_from_search' => false) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2938
			if ( empty( $in_search_post_types ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2939
				$where .= ' AND 1=0 ';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2940
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2941
				$where .= " AND $wpdb->posts.post_type IN ('" . join("', '", $in_search_post_types ) . "')";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2942
		} elseif ( !empty( $post_type ) && is_array( $post_type ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2943
			$where .= " AND $wpdb->posts.post_type IN ('" . join("', '", $post_type) . "')";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2944
		} elseif ( ! empty( $post_type ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2945
			$where .= " AND $wpdb->posts.post_type = '$post_type'";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2946
			$post_type_object = get_post_type_object ( $post_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2947
		} elseif ( $this->is_attachment ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2948
			$where .= " AND $wpdb->posts.post_type = 'attachment'";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2949
			$post_type_object = get_post_type_object ( 'attachment' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2950
		} elseif ( $this->is_page ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2951
			$where .= " AND $wpdb->posts.post_type = 'page'";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2952
			$post_type_object = get_post_type_object ( 'page' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2953
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2954
			$where .= " AND $wpdb->posts.post_type = 'post'";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2955
			$post_type_object = get_post_type_object ( 'post' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2956
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2957
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2958
		$edit_cap = 'edit_post';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2959
		$read_cap = 'read_post';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2960
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2961
		if ( ! empty( $post_type_object ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2962
			$edit_others_cap = $post_type_object->cap->edit_others_posts;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2963
			$read_private_cap = $post_type_object->cap->read_private_posts;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2964
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2965
			$edit_others_cap = 'edit_others_' . $post_type_cap . 's';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2966
			$read_private_cap = 'read_private_' . $post_type_cap . 's';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2967
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2968
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2969
		$user_id = get_current_user_id();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2970
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2971
		$q_status = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2972
		if ( ! empty( $q['post_status'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2973
			$statuswheres = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2974
			$q_status = $q['post_status'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2975
			if ( ! is_array( $q_status ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2976
				$q_status = explode(',', $q_status);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2977
			$r_status = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2978
			$p_status = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2979
			$e_status = array();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2980
			if ( in_array( 'any', $q_status ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2981
				foreach ( get_post_stati( array( 'exclude_from_search' => true ) ) as $status ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2982
					if ( ! in_array( $status, $q_status ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2983
						$e_status[] = "$wpdb->posts.post_status <> '$status'";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2984
					}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2985
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2986
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2987
				foreach ( get_post_stati() as $status ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2988
					if ( in_array( $status, $q_status ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2989
						if ( 'private' == $status )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2990
							$p_status[] = "$wpdb->posts.post_status = '$status'";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2991
						else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2992
							$r_status[] = "$wpdb->posts.post_status = '$status'";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2993
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2994
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2995
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2996
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2997
			if ( empty($q['perm'] ) || 'readable' != $q['perm'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2998
				$r_status = array_merge($r_status, $p_status);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2999
				unset($p_status);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3000
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3001
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3002
			if ( !empty($e_status) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3003
				$statuswheres[] = "(" . join( ' AND ', $e_status ) . ")";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3004
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3005
			if ( !empty($r_status) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3006
				if ( !empty($q['perm'] ) && 'editable' == $q['perm'] && !current_user_can($edit_others_cap) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3007
					$statuswheres[] = "($wpdb->posts.post_author = $user_id " . "AND (" . join( ' OR ', $r_status ) . "))";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3008
				else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3009
					$statuswheres[] = "(" . join( ' OR ', $r_status ) . ")";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3010
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3011
			if ( !empty($p_status) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3012
				if ( !empty($q['perm'] ) && 'readable' == $q['perm'] && !current_user_can($read_private_cap) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3013
					$statuswheres[] = "($wpdb->posts.post_author = $user_id " . "AND (" . join( ' OR ', $p_status ) . "))";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3014
				else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3015
					$statuswheres[] = "(" . join( ' OR ', $p_status ) . ")";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3016
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3017
			if ( $post_status_join ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3018
				$join .= " LEFT JOIN $wpdb->posts AS p2 ON ($wpdb->posts.post_parent = p2.ID) ";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3019
				foreach ( $statuswheres as $index => $statuswhere )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3020
					$statuswheres[$index] = "($statuswhere OR ($wpdb->posts.post_status = 'inherit' AND " . str_replace($wpdb->posts, 'p2', $statuswhere) . "))";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3021
			}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3022
			$where_status = implode( ' OR ', $statuswheres );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3023
			if ( ! empty( $where_status ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3024
				$where .= " AND ($where_status)";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3025
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3026
		} elseif ( !$this->is_singular ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3027
			$where .= " AND ($wpdb->posts.post_status = 'publish'";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3028
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3029
			// Add public states.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3030
			$public_states = get_post_stati( array('public' => true) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3031
			foreach ( (array) $public_states as $state ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3032
				if ( 'publish' == $state ) // Publish is hard-coded above.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3033
					continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3034
				$where .= " OR $wpdb->posts.post_status = '$state'";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3035
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3036
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3037
			if ( $this->is_admin ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3038
				// Add protected states that should show in the admin all list.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3039
				$admin_all_states = get_post_stati( array('protected' => true, 'show_in_admin_all_list' => true) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3040
				foreach ( (array) $admin_all_states as $state )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3041
					$where .= " OR $wpdb->posts.post_status = '$state'";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3042
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3043
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3044
			if ( is_user_logged_in() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3045
				// Add private states that are limited to viewing by the author of a post or someone who has caps to read private states.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3046
				$private_states = get_post_stati( array('private' => true) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3047
				foreach ( (array) $private_states as $state )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3048
					$where .= current_user_can( $read_private_cap ) ? " OR $wpdb->posts.post_status = '$state'" : " OR $wpdb->posts.post_author = $user_id AND $wpdb->posts.post_status = '$state'";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3049
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3050
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3051
			$where .= ')';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3052
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3053
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3054
		/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3055
		 * Apply filters on where and join prior to paging so that any
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3056
		 * manipulations to them are reflected in the paging by day queries.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3057
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3058
		if ( !$q['suppress_filters'] ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3059
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3060
			 * Filter the WHERE clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3061
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3062
			 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3063
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3064
			 * @param string   $where The WHERE clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3065
			 * @param WP_Query &$this The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3066
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3067
			$where = apply_filters_ref_array( 'posts_where', array( $where, &$this ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3068
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3069
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3070
			 * Filter the JOIN clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3071
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3072
			 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3073
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3074
			 * @param string   $where The JOIN clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3075
			 * @param WP_Query &$this The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3076
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3077
			$join = apply_filters_ref_array( 'posts_join', array( $join, &$this ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3078
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3079
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3080
		// Paging
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3081
		if ( empty($q['nopaging']) && !$this->is_singular ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3082
			$page = absint($q['paged']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3083
			if ( !$page )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3084
				$page = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3085
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3086
			if ( empty($q['offset']) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3087
				$pgstrt = absint( ( $page - 1 ) * $q['posts_per_page'] ) . ', ';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3088
			} else { // we're ignoring $page and using 'offset'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3089
				$q['offset'] = absint($q['offset']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3090
				$pgstrt = $q['offset'] . ', ';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3091
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3092
			$limits = 'LIMIT ' . $pgstrt . $q['posts_per_page'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3093
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3094
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3095
		// Comments feeds
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3096
		if ( $this->is_comment_feed && ! $this->is_singular ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3097
			if ( $this->is_archive || $this->is_search ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3098
				$cjoin = "JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) $join ";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3099
				$cwhere = "WHERE comment_approved = '1' $where";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3100
				$cgroupby = "$wpdb->comments.comment_id";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3101
			} else { // Other non singular e.g. front
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3102
				$cjoin = "JOIN $wpdb->posts ON ( $wpdb->comments.comment_post_ID = $wpdb->posts.ID )";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3103
				$cwhere = "WHERE post_status = 'publish' AND comment_approved = '1'";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3104
				$cgroupby = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3105
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3106
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3107
			if ( !$q['suppress_filters'] ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3108
				/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3109
				 * Filter the JOIN clause of the comments feed query before sending.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3110
				 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3111
				 * @since 2.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3112
				 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3113
				 * @param string   $cjoin The JOIN clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3114
				 * @param WP_Query &$this The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3115
				 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3116
				$cjoin = apply_filters_ref_array( 'comment_feed_join', array( $cjoin, &$this ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3117
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3118
				/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3119
				 * Filter the WHERE clause of the comments feed query before sending.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3120
				 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3121
				 * @since 2.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3122
				 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3123
				 * @param string   $cwhere The WHERE clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3124
				 * @param WP_Query &$this  The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3125
				 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3126
				$cwhere = apply_filters_ref_array( 'comment_feed_where', array( $cwhere, &$this ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3127
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3128
				/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3129
				 * Filter the GROUP BY clause of the comments feed query before sending.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3130
				 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3131
				 * @since 2.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3132
				 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3133
				 * @param string   $cgroupby The GROUP BY clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3134
				 * @param WP_Query &$this    The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3135
				 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3136
				$cgroupby = apply_filters_ref_array( 'comment_feed_groupby', array( $cgroupby, &$this ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3137
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3138
				/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3139
				 * Filter the ORDER BY clause of the comments feed query before sending.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3140
				 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3141
				 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3142
				 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3143
				 * @param string   $corderby The ORDER BY clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3144
				 * @param WP_Query &$this    The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3145
				 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3146
				$corderby = apply_filters_ref_array( 'comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3147
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3148
				/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3149
				 * Filter the LIMIT clause of the comments feed query before sending.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3150
				 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3151
				 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3152
				 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3153
				 * @param string   $climits The JOIN clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3154
				 * @param WP_Query &$this   The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3155
				 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3156
				$climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option('posts_per_rss'), &$this ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3157
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3158
			$cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3159
			$corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3160
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3161
			$this->comments = (array) $wpdb->get_results("SELECT $distinct $wpdb->comments.* FROM $wpdb->comments $cjoin $cwhere $cgroupby $corderby $climits");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3162
			$this->comment_count = count($this->comments);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3163
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3164
			$post_ids = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3165
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3166
			foreach ( $this->comments as $comment )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3167
				$post_ids[] = (int) $comment->comment_post_ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3168
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3169
			$post_ids = join(',', $post_ids);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3170
			$join = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3171
			if ( $post_ids )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3172
				$where = "AND $wpdb->posts.ID IN ($post_ids) ";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3173
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3174
				$where = "AND 0";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3175
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3176
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3177
		$pieces = array( 'where', 'groupby', 'join', 'orderby', 'distinct', 'fields', 'limits' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3178
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3179
		/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3180
		 * Apply post-paging filters on where and join. Only plugins that
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3181
		 * manipulate paging queries should use these hooks.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3182
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3183
		if ( !$q['suppress_filters'] ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3184
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3185
			 * Filter the WHERE clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3186
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3187
			 * Specifically for manipulating paging queries.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3188
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3189
			 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3190
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3191
			 * @param string   $where The WHERE clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3192
			 * @param WP_Query &$this The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3193
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3194
			$where = apply_filters_ref_array( 'posts_where_paged', array( $where, &$this ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3195
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3196
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3197
			 * Filter the GROUP BY clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3198
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3199
			 * @since 2.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3200
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3201
			 * @param string   $groupby The GROUP BY clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3202
			 * @param WP_Query &$this   The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3203
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3204
			$groupby = apply_filters_ref_array( 'posts_groupby', array( $groupby, &$this ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3205
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3206
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3207
			 * Filter the JOIN clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3208
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3209
			 * Specifically for manipulating paging queries.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3210
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3211
			 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3212
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3213
			 * @param string   $join  The JOIN clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3214
			 * @param WP_Query &$this The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3215
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3216
			$join = apply_filters_ref_array( 'posts_join_paged', array( $join, &$this ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3217
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3218
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3219
			 * Filter the ORDER BY clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3220
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3221
			 * @since 1.5.1
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3222
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3223
			 * @param string   $orderby The ORDER BY clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3224
			 * @param WP_Query &$this   The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3225
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3226
			$orderby = apply_filters_ref_array( 'posts_orderby', array( $orderby, &$this ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3227
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3228
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3229
			 * Filter the DISTINCT clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3230
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3231
			 * @since 2.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3232
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3233
			 * @param string   $distinct The DISTINCT clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3234
			 * @param WP_Query &$this    The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3235
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3236
			$distinct = apply_filters_ref_array( 'posts_distinct', array( $distinct, &$this ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3237
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3238
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3239
			 * Filter the LIMIT clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3240
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3241
			 * @since 2.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3242
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3243
			 * @param string   $limits The LIMIT clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3244
			 * @param WP_Query &$this  The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3245
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3246
			$limits = apply_filters_ref_array( 'post_limits', array( $limits, &$this ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3247
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3248
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3249
			 * Filter the SELECT clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3250
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3251
			 * @since 2.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3252
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3253
			 * @param string   $fields The SELECT clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3254
			 * @param WP_Query &$this  The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3255
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3256
			$fields = apply_filters_ref_array( 'posts_fields', array( $fields, &$this ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3257
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3258
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3259
			 * Filter all query clauses at once, for convenience.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3260
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3261
			 * Covers the WHERE, GROUP BY, JOIN, ORDER BY, DISTINCT,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3262
			 * fields (SELECT), and LIMITS clauses.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3263
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3264
			 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3265
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3266
			 * @param array    $clauses The list of clauses for the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3267
			 * @param WP_Query &$this   The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3268
			 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3269
			$clauses = (array) apply_filters_ref_array( 'posts_clauses', array( compact( $pieces ), &$this ) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3270
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3271
			$where = isset( $clauses[ 'where' ] ) ? $clauses[ 'where' ] : '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3272
			$groupby = isset( $clauses[ 'groupby' ] ) ? $clauses[ 'groupby' ] : '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3273
			$join = isset( $clauses[ 'join' ] ) ? $clauses[ 'join' ] : '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3274
			$orderby = isset( $clauses[ 'orderby' ] ) ? $clauses[ 'orderby' ] : '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3275
			$distinct = isset( $clauses[ 'distinct' ] ) ? $clauses[ 'distinct' ] : '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3276
			$fields = isset( $clauses[ 'fields' ] ) ? $clauses[ 'fields' ] : '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3277
			$limits = isset( $clauses[ 'limits' ] ) ? $clauses[ 'limits' ] : '';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3278
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3279
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3280
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3281
		 * Fires to announce the query's current selection parameters.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3282
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3283
		 * For use by caching plugins.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3284
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3285
		 * @since 2.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3286
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3287
		 * @param string $selection The assembled selection query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3288
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3289
		do_action( 'posts_selection', $where . $groupby . $orderby . $limits . $join );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3290
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3291
		/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3292
		 * Filter again for the benefit of caching plugins.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3293
		 * Regular plugins should use the hooks above.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3294
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3295
		if ( !$q['suppress_filters'] ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3296
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3297
			 * Filter the WHERE clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3298
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3299
			 * For use by caching plugins.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3300
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3301
			 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3302
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3303
			 * @param string   $where The WHERE clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3304
			 * @param WP_Query &$this The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3305
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3306
			$where = apply_filters_ref_array( 'posts_where_request', array( $where, &$this ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3307
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3308
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3309
			 * Filter the GROUP BY clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3310
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3311
			 * For use by caching plugins.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3312
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3313
			 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3314
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3315
			 * @param string   $groupby The GROUP BY clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3316
			 * @param WP_Query &$this   The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3317
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3318
			$groupby = apply_filters_ref_array( 'posts_groupby_request', array( $groupby, &$this ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3319
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3320
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3321
			 * Filter the JOIN clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3322
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3323
			 * For use by caching plugins.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3324
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3325
			 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3326
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3327
			 * @param string   $join  The JOIN clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3328
			 * @param WP_Query &$this The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3329
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3330
			$join = apply_filters_ref_array( 'posts_join_request', array( $join, &$this ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3331
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3332
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3333
			 * Filter the ORDER BY clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3334
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3335
			 * For use by caching plugins.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3336
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3337
			 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3338
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3339
			 * @param string   $orderby The ORDER BY clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3340
			 * @param WP_Query &$this   The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3341
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3342
			$orderby = apply_filters_ref_array( 'posts_orderby_request', array( $orderby, &$this ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3343
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3344
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3345
			 * Filter the DISTINCT clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3346
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3347
			 * For use by caching plugins.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3348
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3349
			 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3350
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3351
			 * @param string   $distinct The DISTINCT clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3352
			 * @param WP_Query &$this    The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3353
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3354
			$distinct = apply_filters_ref_array( 'posts_distinct_request', array( $distinct, &$this ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3355
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3356
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3357
			 * Filter the SELECT clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3358
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3359
			 * For use by caching plugins.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3360
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3361
			 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3362
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3363
			 * @param string   $fields The SELECT clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3364
			 * @param WP_Query &$this  The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3365
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3366
			$fields = apply_filters_ref_array( 'posts_fields_request', array( $fields, &$this ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3367
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3368
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3369
			 * Filter the LIMIT clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3370
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3371
			 * For use by caching plugins.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3372
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3373
			 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3374
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3375
			 * @param string   $limits The LIMIT clause of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3376
			 * @param WP_Query &$this  The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3377
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3378
			$limits = apply_filters_ref_array( 'post_limits_request', array( $limits, &$this ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3379
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3380
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3381
			 * Filter all query clauses at once, for convenience.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3382
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3383
			 * For use by caching plugins.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3384
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3385
			 * Covers the WHERE, GROUP BY, JOIN, ORDER BY, DISTINCT,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3386
			 * fields (SELECT), and LIMITS clauses.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3387
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3388
			 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3389
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3390
			 * @param array    $pieces The pieces of the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3391
			 * @param WP_Query &$this  The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3392
			 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3393
			$clauses = (array) apply_filters_ref_array( 'posts_clauses_request', array( compact( $pieces ), &$this ) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3394
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3395
			$where = isset( $clauses[ 'where' ] ) ? $clauses[ 'where' ] : '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3396
			$groupby = isset( $clauses[ 'groupby' ] ) ? $clauses[ 'groupby' ] : '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3397
			$join = isset( $clauses[ 'join' ] ) ? $clauses[ 'join' ] : '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3398
			$orderby = isset( $clauses[ 'orderby' ] ) ? $clauses[ 'orderby' ] : '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3399
			$distinct = isset( $clauses[ 'distinct' ] ) ? $clauses[ 'distinct' ] : '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3400
			$fields = isset( $clauses[ 'fields' ] ) ? $clauses[ 'fields' ] : '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3401
			$limits = isset( $clauses[ 'limits' ] ) ? $clauses[ 'limits' ] : '';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3402
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3403
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3404
		if ( ! empty($groupby) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3405
			$groupby = 'GROUP BY ' . $groupby;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3406
		if ( !empty( $orderby ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3407
			$orderby = 'ORDER BY ' . $orderby;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3408
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3409
		$found_rows = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3410
		if ( !$q['no_found_rows'] && !empty($limits) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3411
			$found_rows = 'SQL_CALC_FOUND_ROWS';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3412
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3413
		$this->request = $old_request = "SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3414
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3415
		if ( !$q['suppress_filters'] ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3416
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3417
			 * Filter the completed SQL query before sending.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3418
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3419
			 * @since 2.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3420
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3421
			 * @param array    $request The complete SQL query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3422
			 * @param WP_Query &$this   The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3423
			 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3424
			$this->request = apply_filters_ref_array( 'posts_request', array( $this->request, &$this ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3425
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3426
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3427
		if ( 'ids' == $q['fields'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3428
			$this->posts = $wpdb->get_col( $this->request );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3429
			$this->posts = array_map( 'intval', $this->posts );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3430
			$this->post_count = count( $this->posts );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3431
			$this->set_found_posts( $q, $limits );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3432
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3433
			return $this->posts;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3434
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3435
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3436
		if ( 'id=>parent' == $q['fields'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3437
			$this->posts = $wpdb->get_results( $this->request );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3438
			$this->post_count = count( $this->posts );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3439
			$this->set_found_posts( $q, $limits );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3440
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3441
			$r = array();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3442
			foreach ( $this->posts as $key => $post ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3443
				$this->posts[ $key ]->ID = (int) $post->ID;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3444
				$this->posts[ $key ]->post_parent = (int) $post->post_parent;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3445
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3446
				$r[ (int) $post->ID ] = (int) $post->post_parent;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3447
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3448
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3449
			return $r;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3450
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3451
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3452
		$split_the_query = ( $old_request == $this->request && "$wpdb->posts.*" == $fields && !empty( $limits ) && $q['posts_per_page'] < 500 );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3453
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3454
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3455
		 * Filter whether to split the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3456
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3457
		 * Splitting the query will cause it to fetch just the IDs of the found posts
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3458
		 * (and then individually fetch each post by ID), rather than fetching every
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3459
		 * complete row at once. One massive result vs. many small results.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3460
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3461
		 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3462
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3463
		 * @param bool     $split_the_query Whether or not to split the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3464
		 * @param WP_Query $this            The WP_Query instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3465
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3466
		$split_the_query = apply_filters( 'split_the_query', $split_the_query, $this );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3467
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3468
		if ( $split_the_query ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3469
			// First get the IDs and then fill in the objects
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3470
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3471
			$this->request = "SELECT $found_rows $distinct $wpdb->posts.ID FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3472
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3473
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3474
			 * Filter the Post IDs SQL request before sending.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3475
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3476
			 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3477
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3478
			 * @param string   $request The post ID request.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3479
			 * @param WP_Query $this    The WP_Query instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3480
			 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3481
			$this->request = apply_filters( 'posts_request_ids', $this->request, $this );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3482
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3483
			$ids = $wpdb->get_col( $this->request );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3484
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3485
			if ( $ids ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3486
				$this->posts = $ids;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3487
				$this->set_found_posts( $q, $limits );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3488
				_prime_post_caches( $ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3489
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3490
				$this->posts = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3491
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3492
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3493
			$this->posts = $wpdb->get_results( $this->request );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3494
			$this->set_found_posts( $q, $limits );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3495
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3496
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3497
		// Convert to WP_Post objects
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3498
		if ( $this->posts )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3499
			$this->posts = array_map( 'get_post', $this->posts );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3500
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3501
		if ( ! $q['suppress_filters'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3502
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3503
			 * Filter the raw post results array, prior to status checks.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3504
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3505
			 * @since 2.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3506
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3507
			 * @param array    $posts The post results array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3508
			 * @param WP_Query &$this The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3509
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3510
			$this->posts = apply_filters_ref_array( 'posts_results', array( $this->posts, &$this ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3511
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3512
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3513
		if ( !empty($this->posts) && $this->is_comment_feed && $this->is_singular ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3514
			/** This filter is documented in wp-includes/query.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3515
			$cjoin = apply_filters_ref_array( 'comment_feed_join', array( '', &$this ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3516
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3517
			/** This filter is documented in wp-includes/query.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3518
			$cwhere = apply_filters_ref_array( 'comment_feed_where', array( "WHERE comment_post_ID = '{$this->posts[0]->ID}' AND comment_approved = '1'", &$this ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3519
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3520
			/** This filter is documented in wp-includes/query.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3521
			$cgroupby = apply_filters_ref_array( 'comment_feed_groupby', array( '', &$this ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3522
			$cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : '';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3523
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3524
			/** This filter is documented in wp-includes/query.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3525
			$corderby = apply_filters_ref_array( 'comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3526
			$corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : '';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3527
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3528
			/** This filter is documented in wp-includes/query.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3529
			$climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option('posts_per_rss'), &$this ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3530
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3531
			$comments_request = "SELECT $wpdb->comments.* FROM $wpdb->comments $cjoin $cwhere $cgroupby $corderby $climits";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3532
			$this->comments = $wpdb->get_results($comments_request);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3533
			$this->comment_count = count($this->comments);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3534
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3535
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3536
		// Check post status to determine if post should be displayed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3537
		if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3538
			$status = get_post_status($this->posts[0]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3539
			$post_status_obj = get_post_status_object($status);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3540
			//$type = get_post_type($this->posts[0]);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3541
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3542
			// If the post_status was specifically requested, let it pass through.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3543
			if ( !$post_status_obj->public && ! in_array( $status, $q_status ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3544
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3545
				if ( ! is_user_logged_in() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3546
					// User must be logged in to view unpublished posts.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3547
					$this->posts = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3548
				} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3549
					if  ( $post_status_obj->protected ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3550
						// User must have edit permissions on the draft to preview.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3551
						if ( ! current_user_can($edit_cap, $this->posts[0]->ID) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3552
							$this->posts = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3553
						} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3554
							$this->is_preview = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3555
							if ( 'future' != $status )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3556
								$this->posts[0]->post_date = current_time('mysql');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3557
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3558
					} elseif ( $post_status_obj->private ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3559
						if ( ! current_user_can($read_cap, $this->posts[0]->ID) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3560
							$this->posts = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3561
					} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3562
						$this->posts = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3563
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3564
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3565
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3566
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3567
			if ( $this->is_preview && $this->posts && current_user_can( $edit_cap, $this->posts[0]->ID ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3568
				/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3569
				 * Filter the single post for preview mode.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3570
				 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3571
				 * @since 2.7.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3572
				 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3573
				 * @param WP_Post  $post_preview  The Post object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3574
				 * @param WP_Query &$this         The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3575
				 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3576
				$this->posts[0] = get_post( apply_filters_ref_array( 'the_preview', array( $this->posts[0], &$this ) ) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3577
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3578
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3579
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3580
		// Put sticky posts at the top of the posts array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3581
		$sticky_posts = get_option('sticky_posts');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3582
		if ( $this->is_home && $page <= 1 && is_array($sticky_posts) && !empty($sticky_posts) && !$q['ignore_sticky_posts'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3583
			$num_posts = count($this->posts);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3584
			$sticky_offset = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3585
			// Loop over posts and relocate stickies to the front.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3586
			for ( $i = 0; $i < $num_posts; $i++ ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3587
				if ( in_array($this->posts[$i]->ID, $sticky_posts) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3588
					$sticky_post = $this->posts[$i];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3589
					// Remove sticky from current position
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3590
					array_splice($this->posts, $i, 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3591
					// Move to front, after other stickies
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3592
					array_splice($this->posts, $sticky_offset, 0, array($sticky_post));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3593
					// Increment the sticky offset. The next sticky will be placed at this offset.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3594
					$sticky_offset++;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3595
					// Remove post from sticky posts array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3596
					$offset = array_search($sticky_post->ID, $sticky_posts);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3597
					unset( $sticky_posts[$offset] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3598
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3599
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3600
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3601
			// If any posts have been excluded specifically, Ignore those that are sticky.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3602
			if ( !empty($sticky_posts) && !empty($q['post__not_in']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3603
				$sticky_posts = array_diff($sticky_posts, $q['post__not_in']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3604
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3605
			// Fetch sticky posts that weren't in the query results
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3606
			if ( !empty($sticky_posts) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3607
				$stickies = get_posts( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3608
					'post__in' => $sticky_posts,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3609
					'post_type' => $post_type,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3610
					'post_status' => 'publish',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3611
					'nopaging' => true
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3612
				) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3613
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3614
				foreach ( $stickies as $sticky_post ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3615
					array_splice( $this->posts, $sticky_offset, 0, array( $sticky_post ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3616
					$sticky_offset++;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3617
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3618
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3619
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3620
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3621
		if ( ! $q['suppress_filters'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3622
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3623
			 * Filter the array of retrieved posts after they've been fetched and
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3624
			 * internally processed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3625
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3626
			 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3627
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3628
			 * @param array    $posts The array of retrieved posts.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3629
			 * @param WP_Query &$this The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3630
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3631
			$this->posts = apply_filters_ref_array( 'the_posts', array( $this->posts, &$this ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3632
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3633
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3634
		// Ensure that any posts added/modified via one of the filters above are
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3635
		// of the type WP_Post and are filtered.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3636
		if ( $this->posts ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3637
			$this->post_count = count( $this->posts );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3638
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3639
			$this->posts = array_map( 'get_post', $this->posts );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3640
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3641
			if ( $q['cache_results'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3642
				update_post_caches($this->posts, $post_type, $q['update_post_term_cache'], $q['update_post_meta_cache']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3643
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3644
			$this->post = reset( $this->posts );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3645
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3646
			$this->post_count = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3647
			$this->posts = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3648
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3649
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3650
		return $this->posts;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3651
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3652
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3653
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3654
	 * Set up the amount of found posts and the number of pages (if limit clause was used)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3655
	 * for the current query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3656
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3657
	 * @since 3.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3658
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3659
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3660
	private function set_found_posts( $q, $limits ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3661
		global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3662
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3663
		// Bail if posts is an empty array. Continue if posts is an empty string,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3664
		// null, or false to accommodate caching plugins that fill posts later.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3665
		if ( $q['no_found_rows'] || ( is_array( $this->posts ) && ! $this->posts ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3666
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3667
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3668
		if ( ! empty( $limits ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3669
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3670
			 * Filter the query to run for retrieving the found posts.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3671
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3672
			 * @since 2.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3673
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3674
			 * @param string   $found_posts The query to run to find the found posts.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3675
			 * @param WP_Query &$this       The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3676
			 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3677
			$this->found_posts = $wpdb->get_var( apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3678
		} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3679
			$this->found_posts = count( $this->posts );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3680
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3681
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3682
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3683
		 * Filter the number of found posts for the query.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3684
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3685
		 * @since 2.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3686
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3687
		 * @param int      $found_posts The number of posts found.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3688
		 * @param WP_Query &$this       The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3689
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3690
		$this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3691
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3692
		if ( ! empty( $limits ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3693
			$this->max_num_pages = ceil( $this->found_posts / $q['posts_per_page'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3694
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3695
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3696
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3697
	 * Set up the next post and iterate current post index.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3698
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3699
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3700
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3701
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3702
	 * @return WP_Post Next post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3703
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3704
	public function next_post() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3705
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3706
		$this->current_post++;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3707
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3708
		$this->post = $this->posts[$this->current_post];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3709
		return $this->post;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3710
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3711
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3712
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3713
	 * Sets up the current post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3714
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3715
	 * Retrieves the next post, sets up the post, sets the 'in the loop'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3716
	 * property to true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3717
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3718
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3719
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3720
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3721
	public function the_post() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3722
		global $post;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3723
		$this->in_the_loop = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3724
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3725
		if ( $this->current_post == -1 ) // loop has just started
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3726
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3727
			 * Fires once the loop is started.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3728
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3729
			 * @since 2.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3730
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3731
			 * @param WP_Query &$this The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3732
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3733
			do_action_ref_array( 'loop_start', array( &$this ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3734
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3735
		$post = $this->next_post();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3736
		$this->setup_postdata( $post );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3737
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3738
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3739
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3740
	 * Whether there are more posts available in the loop.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3741
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3742
	 * Calls action 'loop_end', when the loop is complete.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3743
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3744
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3745
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3746
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3747
	 * @return bool True if posts are available, false if end of loop.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3748
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3749
	public function have_posts() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3750
		if ( $this->current_post + 1 < $this->post_count ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3751
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3752
		} elseif ( $this->current_post + 1 == $this->post_count && $this->post_count > 0 ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3753
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3754
			 * Fires once the loop has ended.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3755
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3756
			 * @since 2.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3757
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3758
			 * @param WP_Query &$this The WP_Query instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3759
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3760
			do_action_ref_array( 'loop_end', array( &$this ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3761
			// Do some cleaning up after the loop
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3762
			$this->rewind_posts();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3763
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3764
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3765
		$this->in_the_loop = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3766
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3767
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3768
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3769
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3770
	 * Rewind the posts and reset post index.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3771
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3772
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3773
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3774
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3775
	public function rewind_posts() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3776
		$this->current_post = -1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3777
		if ( $this->post_count > 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3778
			$this->post = $this->posts[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3779
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3780
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3781
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3782
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3783
	 * Iterate current comment index and return comment object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3784
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3785
	 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3786
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3787
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3788
	 * @return object Comment object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3789
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3790
	public function next_comment() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3791
		$this->current_comment++;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3792
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3793
		$this->comment = $this->comments[$this->current_comment];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3794
		return $this->comment;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3795
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3796
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3797
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3798
	 * Sets up the current comment.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3799
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3800
	 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3801
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3802
	 * @global object $comment Current comment.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3803
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3804
	public function the_comment() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3805
		global $comment;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3806
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3807
		$comment = $this->next_comment();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3808
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3809
		if ( $this->current_comment == 0 ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3810
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3811
			 * Fires once the comment loop is started.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3812
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3813
			 * @since 2.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3814
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3815
			do_action( 'comment_loop_start' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3816
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3817
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3818
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3819
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3820
	 * Whether there are more comments available.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3821
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3822
	 * Automatically rewinds comments when finished.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3823
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3824
	 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3825
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3826
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3827
	 * @return bool True, if more comments. False, if no more posts.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3828
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3829
	public function have_comments() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3830
		if ( $this->current_comment + 1 < $this->comment_count ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3831
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3832
		} elseif ( $this->current_comment + 1 == $this->comment_count ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3833
			$this->rewind_comments();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3834
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3835
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3836
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3837
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3838
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3839
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3840
	 * Rewind the comments, resets the comment index and comment to first.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3841
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3842
	 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3843
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3844
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3845
	public function rewind_comments() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3846
		$this->current_comment = -1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3847
		if ( $this->comment_count > 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3848
			$this->comment = $this->comments[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3849
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3850
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3851
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3852
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3853
	 * Sets up the WordPress query by parsing query string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3854
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3855
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3856
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3857
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3858
	 * @param string $query URL query string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3859
	 * @return array List of posts.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3860
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3861
	public function query( $query ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3862
		$this->init();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3863
		$this->query = $this->query_vars = wp_parse_args( $query );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3864
		return $this->get_posts();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3865
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3866
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3867
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3868
	 * Retrieve queried object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3869
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3870
	 * If queried object is not set, then the queried object will be set from
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3871
	 * the category, tag, taxonomy, posts page, single post, page, or author
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3872
	 * query variable. After it is set up, it will be returned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3873
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3874
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3875
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3876
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3877
	 * @return object
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3878
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3879
	public function get_queried_object() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3880
		if ( isset($this->queried_object) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3881
			return $this->queried_object;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3882
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3883
		$this->queried_object = null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3884
		$this->queried_object_id = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3885
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3886
		if ( $this->is_category || $this->is_tag || $this->is_tax ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3887
			if ( $this->is_category ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3888
				if ( $this->get( 'cat' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3889
					$term = get_term( $this->get( 'cat' ), 'category' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3890
				} elseif ( $this->get( 'category_name' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3891
					$term = get_term_by( 'slug', $this->get( 'category_name' ), 'category' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3892
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3893
			} elseif ( $this->is_tag ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3894
				if ( $this->get( 'tag_id' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3895
					$term = get_term( $this->get( 'tag_id' ), 'post_tag' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3896
				} elseif ( $this->get( 'tag' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3897
					$term = get_term_by( 'slug', $this->get( 'tag' ), 'post_tag' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3898
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3899
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3900
				// For other tax queries, grab the first term from the first clause.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3901
				$tax_query_in_and = wp_list_filter( $this->tax_query->queried_terms, array( 'operator' => 'NOT IN' ), 'NOT' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3902
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3903
				if ( ! empty( $tax_query_in_and ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3904
					$queried_taxonomies = array_keys( $tax_query_in_and );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3905
					$matched_taxonomy = reset( $queried_taxonomies );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3906
					$query = $tax_query_in_and[ $matched_taxonomy ];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3907
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3908
					if ( $query['terms'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3909
						if ( 'term_id' == $query['field'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3910
							$term = get_term( reset( $query['terms'] ), $matched_taxonomy );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3911
						} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3912
							$term = get_term_by( $query['field'], reset( $query['terms'] ), $matched_taxonomy );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3913
						}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3914
					}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3915
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3916
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3917
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3918
			if ( ! empty( $term ) && ! is_wp_error( $term ) )  {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3919
				$this->queried_object = $term;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3920
				$this->queried_object_id = (int) $term->term_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3921
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3922
				if ( $this->is_category && 'category' === $this->queried_object->taxonomy )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3923
					_make_cat_compat( $this->queried_object );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3924
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3925
		} elseif ( $this->is_post_type_archive ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3926
			$post_type = $this->get( 'post_type' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3927
			if ( is_array( $post_type ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3928
				$post_type = reset( $post_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3929
			$this->queried_object = get_post_type_object( $post_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3930
		} elseif ( $this->is_posts_page ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3931
			$page_for_posts = get_option('page_for_posts');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3932
			$this->queried_object = get_post( $page_for_posts );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3933
			$this->queried_object_id = (int) $this->queried_object->ID;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3934
		} elseif ( $this->is_singular && ! empty( $this->post ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3935
			$this->queried_object = $this->post;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3936
			$this->queried_object_id = (int) $this->post->ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3937
		} elseif ( $this->is_author ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3938
			$this->queried_object_id = (int) $this->get('author');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3939
			$this->queried_object = get_userdata( $this->queried_object_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3940
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3941
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3942
		return $this->queried_object;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3943
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3944
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3945
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3946
	 * Retrieve ID of the current queried object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3947
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3948
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3949
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3950
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3951
	 * @return int
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3952
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3953
	public function get_queried_object_id() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3954
		$this->get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3955
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3956
		if ( isset($this->queried_object_id) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3957
			return $this->queried_object_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3958
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3959
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3960
		return 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3961
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3962
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3963
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3964
	 * Constructor.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3965
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3966
	 * Sets up the WordPress query, if parameter is not empty.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3967
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3968
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3969
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3970
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3971
	 * @param string|array $query URL query string or array of vars.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3972
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3973
	public function __construct($query = '') {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3974
		if ( ! empty($query) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3975
			$this->query($query);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3976
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3977
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3978
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3979
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3980
	 * Make private properties readable for backwards compatibility.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3981
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3982
	 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3983
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3984
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3985
	 * @param string $name Property to get.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3986
	 * @return mixed Property.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3987
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3988
	public function __get( $name ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3989
		if ( in_array( $name, $this->compat_fields ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3990
			return $this->$name;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3991
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3992
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3993
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3994
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3995
	 * Make private properties checkable for backwards compatibility.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3996
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3997
	 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3998
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3999
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4000
	 * @param string $name Property to check if set.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4001
	 * @return bool Whether the property is set.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4002
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4003
	public function __isset( $name ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4004
		if ( in_array( $name, $this->compat_fields ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4005
			return isset( $this->$name );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4006
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4007
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4008
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4009
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4010
	 * Make private/protected methods readable for backwards compatibility.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4011
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4012
	 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4013
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4014
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4015
	 * @param callable $name      Method to call.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4016
	 * @param array    $arguments Arguments to pass when calling.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4017
	 * @return mixed|bool Return value of the callback, false otherwise.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4018
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4019
	public function __call( $name, $arguments ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4020
		if ( in_array( $name, $this->compat_methods ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4021
			return call_user_func_array( array( $this, $name ), $arguments );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4022
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4023
		return false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4024
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4025
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4026
	/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4027
 	 * Is the query for an existing archive page?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4028
 	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4029
 	 * Month, Year, Category, Author, Post Type archive...
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4030
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4031
 	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4032
 	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4033
 	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4034
 	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4035
	public function is_archive() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4036
		return (bool) $this->is_archive;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4037
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4038
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4039
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4040
	 * Is the query for an existing post type archive page?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4041
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4042
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4043
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4044
	 * @param mixed $post_types Optional. Post type or array of posts types to check against.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4045
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4046
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4047
	public function is_post_type_archive( $post_types = '' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4048
		if ( empty( $post_types ) || ! $this->is_post_type_archive )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4049
			return (bool) $this->is_post_type_archive;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4050
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4051
		$post_type = $this->get( 'post_type' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4052
		if ( is_array( $post_type ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4053
			$post_type = reset( $post_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4054
		$post_type_object = get_post_type_object( $post_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4055
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4056
		return in_array( $post_type_object->name, (array) $post_types );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4057
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4058
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4059
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4060
	 * Is the query for an existing attachment page?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4061
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4062
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4063
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4064
	 * @param mixed $attachment Attachment ID, title, slug, or array of such.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4065
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4066
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4067
	public function is_attachment( $attachment = '' ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4068
		if ( ! $this->is_attachment ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4069
			return false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4070
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4071
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4072
		if ( empty( $attachment ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4073
			return true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4074
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4075
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4076
		$attachment = (array) $attachment;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4077
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4078
		$post_obj = $this->get_queried_object();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4079
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4080
		if ( in_array( (string) $post_obj->ID, $attachment ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4081
			return true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4082
		} elseif ( in_array( $post_obj->post_title, $attachment ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4083
			return true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4084
		} elseif ( in_array( $post_obj->post_name, $attachment ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4085
			return true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4086
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4087
		return false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4088
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4089
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4090
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4091
	 * Is the query for an existing author archive page?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4092
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4093
	 * If the $author parameter is specified, this function will additionally
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4094
	 * check if the query is for one of the authors specified.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4095
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4096
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4097
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4098
	 * @param mixed $author Optional. User ID, nickname, nicename, or array of User IDs, nicknames, and nicenames
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4099
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4100
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4101
	public function is_author( $author = '' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4102
		if ( !$this->is_author )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4103
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4104
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4105
		if ( empty($author) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4106
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4107
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4108
		$author_obj = $this->get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4109
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4110
		$author = (array) $author;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4111
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4112
		if ( in_array( (string) $author_obj->ID, $author ) )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4113
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4114
		elseif ( in_array( $author_obj->nickname, $author ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4115
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4116
		elseif ( in_array( $author_obj->user_nicename, $author ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4117
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4118
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4119
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4120
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4121
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4122
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4123
	 * Is the query for an existing category archive page?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4124
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4125
	 * If the $category parameter is specified, this function will additionally
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4126
	 * check if the query is for one of the categories specified.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4127
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4128
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4129
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4130
	 * @param mixed $category Optional. Category ID, name, slug, or array of Category IDs, names, and slugs.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4131
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4132
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4133
	public function is_category( $category = '' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4134
		if ( !$this->is_category )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4135
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4136
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4137
		if ( empty($category) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4138
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4139
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4140
		$cat_obj = $this->get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4141
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4142
		$category = (array) $category;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4143
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4144
		if ( in_array( (string) $cat_obj->term_id, $category ) )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4145
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4146
		elseif ( in_array( $cat_obj->name, $category ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4147
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4148
		elseif ( in_array( $cat_obj->slug, $category ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4149
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4150
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4151
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4152
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4153
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4154
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4155
	 * Is the query for an existing tag archive page?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4156
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4157
	 * If the $tag parameter is specified, this function will additionally
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4158
	 * check if the query is for one of the tags specified.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4159
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4160
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4161
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4162
	 * @param mixed $tag Optional. Tag ID, name, slug, or array of Tag IDs, names, and slugs.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4163
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4164
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4165
	public function is_tag( $tag = '' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4166
		if ( ! $this->is_tag )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4167
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4168
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4169
		if ( empty( $tag ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4170
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4171
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4172
		$tag_obj = $this->get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4173
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4174
		$tag = (array) $tag;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4175
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4176
		if ( in_array( (string) $tag_obj->term_id, $tag ) )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4177
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4178
		elseif ( in_array( $tag_obj->name, $tag ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4179
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4180
		elseif ( in_array( $tag_obj->slug, $tag ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4181
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4182
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4183
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4184
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4185
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4186
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4187
	 * Is the query for an existing taxonomy archive page?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4188
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4189
	 * If the $taxonomy parameter is specified, this function will additionally
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4190
	 * check if the query is for that specific $taxonomy.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4191
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4192
	 * If the $term parameter is specified in addition to the $taxonomy parameter,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4193
	 * this function will additionally check if the query is for one of the terms
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4194
	 * specified.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4195
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4196
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4197
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4198
	 * @param mixed $taxonomy Optional. Taxonomy slug or slugs.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4199
	 * @param mixed $term     Optional. Term ID, name, slug or array of Term IDs, names, and slugs.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4200
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4201
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4202
	public function is_tax( $taxonomy = '', $term = '' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4203
		global $wp_taxonomies;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4204
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4205
		if ( !$this->is_tax )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4206
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4207
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4208
		if ( empty( $taxonomy ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4209
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4210
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4211
		$queried_object = $this->get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4212
		$tax_array = array_intersect( array_keys( $wp_taxonomies ), (array) $taxonomy );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4213
		$term_array = (array) $term;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4214
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4215
		// Check that the taxonomy matches.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4216
		if ( ! ( isset( $queried_object->taxonomy ) && count( $tax_array ) && in_array( $queried_object->taxonomy, $tax_array ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4217
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4218
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4219
		// Only a Taxonomy provided.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4220
		if ( empty( $term ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4221
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4222
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4223
		return isset( $queried_object->term_id ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4224
			count( array_intersect(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4225
				array( $queried_object->term_id, $queried_object->name, $queried_object->slug ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4226
				$term_array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4227
			) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4228
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4229
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4230
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4231
	 * Whether the current URL is within the comments popup window.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4232
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4233
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4234
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4235
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4236
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4237
	public function is_comments_popup() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4238
		return (bool) $this->is_comments_popup;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4239
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4240
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4241
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4242
	 * Is the query for an existing date archive?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4243
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4244
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4245
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4246
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4247
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4248
	public function is_date() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4249
		return (bool) $this->is_date;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4250
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4251
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4252
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4253
	 * Is the query for an existing day archive?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4254
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4255
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4256
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4257
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4258
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4259
	public function is_day() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4260
		return (bool) $this->is_day;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4261
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4262
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4263
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4264
	 * Is the query for a feed?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4265
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4266
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4267
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4268
	 * @param string|array $feeds Optional feed types to check.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4269
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4270
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4271
	public function is_feed( $feeds = '' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4272
		if ( empty( $feeds ) || ! $this->is_feed )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4273
			return (bool) $this->is_feed;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4274
		$qv = $this->get( 'feed' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4275
		if ( 'feed' == $qv )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4276
			$qv = get_default_feed();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4277
		return in_array( $qv, (array) $feeds );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4278
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4279
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4280
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4281
	 * Is the query for a comments feed?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4282
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4283
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4284
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4285
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4286
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4287
	public function is_comment_feed() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4288
		return (bool) $this->is_comment_feed;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4289
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4290
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4291
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4292
	 * Is the query for the front page of the site?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4293
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4294
	 * This is for what is displayed at your site's main URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4295
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4296
	 * Depends on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_on_front'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4297
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4298
	 * If you set a static page for the front page of your site, this function will return
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4299
	 * true when viewing that page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4300
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4301
	 * Otherwise the same as @see WP_Query::is_home()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4302
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4303
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4304
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4305
	 * @return bool True, if front of site.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4306
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4307
	public function is_front_page() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4308
		// most likely case
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4309
		if ( 'posts' == get_option( 'show_on_front') && $this->is_home() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4310
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4311
		elseif ( 'page' == get_option( 'show_on_front') && get_option( 'page_on_front' ) && $this->is_page( get_option( 'page_on_front' ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4312
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4313
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4314
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4315
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4316
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4317
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4318
	 * Is the query for the blog homepage?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4319
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4320
	 * This is the page which shows the time based blog content of your site.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4321
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4322
	 * Depends on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_for_posts'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4323
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4324
	 * If you set a static page for the front page of your site, this function will return
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4325
	 * true only on the page you set as the "Posts page".
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4326
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4327
	 * @see WP_Query::is_front_page()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4328
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4329
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4330
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4331
	 * @return bool True if blog view homepage.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4332
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4333
	public function is_home() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4334
		return (bool) $this->is_home;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4335
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4336
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4337
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4338
	 * Is the query for an existing month archive?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4339
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4340
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4341
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4342
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4343
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4344
	public function is_month() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4345
		return (bool) $this->is_month;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4346
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4347
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4348
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4349
	 * Is the query for an existing single page?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4350
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4351
	 * If the $page parameter is specified, this function will additionally
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4352
	 * check if the query is for one of the pages specified.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4353
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4354
	 * @see WP_Query::is_single()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4355
	 * @see WP_Query::is_singular()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4356
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4357
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4358
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4359
	 * @param mixed $page Page ID, title, slug, path, or array of such.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4360
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4361
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4362
	public function is_page( $page = '' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4363
		if ( !$this->is_page )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4364
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4365
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4366
		if ( empty( $page ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4367
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4368
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4369
		$page_obj = $this->get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4370
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4371
		$page = (array) $page;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4372
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4373
		if ( in_array( (string) $page_obj->ID, $page ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4374
			return true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4375
		} elseif ( in_array( $page_obj->post_title, $page ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4376
			return true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4377
		} elseif ( in_array( $page_obj->post_name, $page ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4378
			return true;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4379
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4380
			foreach ( $page as $pagepath ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4381
				if ( ! strpos( $pagepath, '/' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4382
					continue;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4383
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4384
				$pagepath_obj = get_page_by_path( $pagepath );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4385
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4386
				if ( $pagepath_obj && ( $pagepath_obj->ID == $page_obj->ID ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4387
					return true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4388
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4389
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4390
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4391
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4392
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4393
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4394
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4395
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4396
	 * Is the query for paged result and not for the first page?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4397
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4398
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4399
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4400
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4401
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4402
	public function is_paged() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4403
		return (bool) $this->is_paged;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4404
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4405
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4406
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4407
	 * Is the query for a post or page preview?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4408
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4409
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4410
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4411
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4412
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4413
	public function is_preview() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4414
		return (bool) $this->is_preview;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4415
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4416
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4417
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4418
	 * Is the query for the robots file?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4419
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4420
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4421
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4422
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4423
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4424
	public function is_robots() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4425
		return (bool) $this->is_robots;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4426
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4427
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4428
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4429
	 * Is the query for a search?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4430
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4431
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4432
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4433
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4434
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4435
	public function is_search() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4436
		return (bool) $this->is_search;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4437
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4438
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4439
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4440
	 * Is the query for an existing single post?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4441
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4442
	 * Works for any post type, except attachments and pages
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4443
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4444
	 * If the $post parameter is specified, this function will additionally
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4445
	 * check if the query is for one of the Posts specified.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4446
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4447
	 * @see WP_Query::is_page()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4448
	 * @see WP_Query::is_singular()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4449
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4450
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4451
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4452
	 * @param mixed $post Post ID, title, slug, path, or array of such.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4453
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4454
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4455
	public function is_single( $post = '' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4456
		if ( !$this->is_single )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4457
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4458
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4459
		if ( empty($post) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4460
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4461
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4462
		$post_obj = $this->get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4463
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4464
		$post = (array) $post;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4465
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4466
		if ( in_array( (string) $post_obj->ID, $post ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4467
			return true;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4468
		} elseif ( in_array( $post_obj->post_title, $post ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4469
			return true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4470
		} elseif ( in_array( $post_obj->post_name, $post ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4471
			return true;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4472
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4473
			foreach ( $post as $postpath ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4474
				if ( ! strpos( $postpath, '/' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4475
					continue;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4476
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4477
				$postpath_obj = get_page_by_path( $postpath, OBJECT, $post_obj->post_type );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4478
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4479
				if ( $postpath_obj && ( $postpath_obj->ID == $post_obj->ID ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4480
					return true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4481
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4482
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4483
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4484
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4485
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4486
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4487
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4488
	 * Is the query for an existing single post of any post type (post, attachment, page, ... )?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4489
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4490
	 * If the $post_types parameter is specified, this function will additionally
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4491
	 * check if the query is for one of the Posts Types specified.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4492
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4493
	 * @see WP_Query::is_page()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4494
	 * @see WP_Query::is_single()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4495
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4496
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4497
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4498
	 * @param mixed $post_types Optional. Post Type or array of Post Types
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4499
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4500
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4501
	public function is_singular( $post_types = '' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4502
		if ( empty( $post_types ) || !$this->is_singular )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4503
			return (bool) $this->is_singular;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4504
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4505
		$post_obj = $this->get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4506
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4507
		return in_array( $post_obj->post_type, (array) $post_types );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4508
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4509
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4510
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4511
	 * Is the query for a specific time?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4512
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4513
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4514
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4515
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4516
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4517
	public function is_time() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4518
		return (bool) $this->is_time;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4519
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4520
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4521
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4522
	 * Is the query for a trackback endpoint call?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4523
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4524
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4525
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4526
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4527
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4528
	public function is_trackback() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4529
		return (bool) $this->is_trackback;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4530
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4531
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4532
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4533
	 * Is the query for an existing year archive?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4534
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4535
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4536
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4537
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4538
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4539
	public function is_year() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4540
		return (bool) $this->is_year;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4541
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4542
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4543
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4544
	 * Is the query a 404 (returns no results)?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4545
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4546
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4547
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4548
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4549
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4550
	public function is_404() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4551
		return (bool) $this->is_404;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4552
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4553
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4554
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4555
	 * Is the query the main query?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4556
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4557
	 * @since 3.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4558
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4559
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4560
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4561
	public function is_main_query() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4562
		global $wp_the_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4563
		return $wp_the_query === $this;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4564
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4565
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4566
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4567
	 * Set up global post data.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4568
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4569
	 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4570
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4571
	 * @param WP_Post $post Post data.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4572
	 * @return bool True when finished.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4573
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4574
	public function setup_postdata( $post ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4575
		global $id, $authordata, $currentday, $currentmonth, $page, $pages, $multipage, $more, $numpages;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4576
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4577
		$id = (int) $post->ID;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4578
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4579
		$authordata = get_userdata($post->post_author);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4580
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4581
		$currentday = mysql2date('d.m.y', $post->post_date, false);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4582
		$currentmonth = mysql2date('m', $post->post_date, false);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4583
		$numpages = 1;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4584
		$multipage = 0;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4585
		$page = $this->get( 'page' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4586
		if ( ! $page )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4587
			$page = 1;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4588
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4589
		/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4590
		 * Force full post content when viewing the permalink for the $post,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4591
		 * or when on an RSS feed. Otherwise respect the 'more' tag.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4592
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4593
		if ( $post->ID === get_queried_object_id() && ( $this->is_page() || $this->is_single() ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4594
			$more = 1;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4595
		} elseif ( $this->is_feed() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4596
			$more = 1;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4597
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4598
			$more = 0;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4599
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4600
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4601
		$content = $post->post_content;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4602
		if ( false !== strpos( $content, '<!--nextpage-->' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4603
			if ( $page > 1 )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4604
				$more = 1;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4605
			$content = str_replace( "\n<!--nextpage-->\n", '<!--nextpage-->', $content );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4606
			$content = str_replace( "\n<!--nextpage-->", '<!--nextpage-->', $content );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4607
			$content = str_replace( "<!--nextpage-->\n", '<!--nextpage-->', $content );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4608
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4609
			// Ignore nextpage at the beginning of the content.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4610
			if ( 0 === strpos( $content, '<!--nextpage-->' ) )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4611
				$content = substr( $content, 15 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4612
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4613
			$pages = explode('<!--nextpage-->', $content);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4614
			$numpages = count($pages);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4615
			if ( $numpages > 1 )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4616
				$multipage = 1;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4617
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4618
			$pages = array( $post->post_content );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4619
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4620
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4621
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4622
		 * Fires once the post data has been setup.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4623
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4624
		 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4625
		 * @since 4.1.0 Introduced `$this` parameter.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4626
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4627
		 * @param WP_Post  &$post The Post object (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4628
		 * @param WP_Query &$this The current Query object (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4629
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4630
		do_action_ref_array( 'the_post', array( &$post, &$this ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4631
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4632
		return true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4633
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4634
	/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4635
	 * After looping through a nested query, this function
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4636
	 * restores the $post global to the current post in this query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4637
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4638
	 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4639
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4640
	public function reset_postdata() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4641
		if ( ! empty( $this->post ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4642
			$GLOBALS['post'] = $this->post;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4643
			setup_postdata( $this->post );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4644
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4645
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4646
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4647
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4648
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4649
 * Redirect old slugs to the correct permalink.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4650
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4651
 * Attempts to find the current slug from the past slugs.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4652
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4653
 * @since 2.1.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4654
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4655
 * @uses $wp_query
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4656
 * @global wpdb $wpdb WordPress database abstraction object.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4657
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4658
 * @return null If no link is found, null is returned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4659
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4660
function wp_old_slug_redirect() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4661
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4662
	if ( is_404() && '' != $wp_query->query_vars['name'] ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4663
		global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4664
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4665
		// Guess the current post_type based on the query vars.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4666
		if ( get_query_var('post_type') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4667
			$post_type = get_query_var('post_type');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4668
		elseif ( !empty($wp_query->query_vars['pagename']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4669
			$post_type = 'page';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4670
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4671
			$post_type = 'post';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4672
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4673
		if ( is_array( $post_type ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4674
			if ( count( $post_type ) > 1 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4675
				return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4676
			$post_type = reset( $post_type );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4677
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4678
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4679
		// Do not attempt redirect for hierarchical post types
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4680
		if ( is_post_type_hierarchical( $post_type ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4681
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4682
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4683
		$query = $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta, $wpdb->posts WHERE ID = post_id AND post_type = %s AND meta_key = '_wp_old_slug' AND meta_value = %s", $post_type, $wp_query->query_vars['name']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4684
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4685
		// if year, monthnum, or day have been specified, make our query more precise
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4686
		// just in case there are multiple identical _wp_old_slug values
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4687
		if ( '' != $wp_query->query_vars['year'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4688
			$query .= $wpdb->prepare(" AND YEAR(post_date) = %d", $wp_query->query_vars['year']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4689
		if ( '' != $wp_query->query_vars['monthnum'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4690
			$query .= $wpdb->prepare(" AND MONTH(post_date) = %d", $wp_query->query_vars['monthnum']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4691
		if ( '' != $wp_query->query_vars['day'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4692
			$query .= $wpdb->prepare(" AND DAYOFMONTH(post_date) = %d", $wp_query->query_vars['day']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4693
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4694
		$id = (int) $wpdb->get_var($query);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4695
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4696
		if ( ! $id )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4697
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4698
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4699
		$link = get_permalink($id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4700
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4701
		if ( !$link )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4702
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4703
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4704
		wp_redirect( $link, 301 ); // Permanent redirect
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4705
		exit;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4706
	endif;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4707
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4708
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4709
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4710
 * Set up global post data.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4711
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4712
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4713
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4714
 * @param object $post Post data.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4715
 * @return bool True when finished.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4716
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4717
function setup_postdata( $post ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4718
	global $wp_query;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4719
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4720
	if ( ! empty( $wp_query ) && $wp_query instanceof WP_Query ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4721
		return $wp_query->setup_postdata( $post );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4722
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4723
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4724
	return false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4725
}