mp-wp_genesis 1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * WordPress Query API
mp-wp_genesis 4 *
mp-wp_genesis 5 * The query API attempts to get which part of WordPress to the user is on. It
mp-wp_genesis 6 * also provides functionality to getting URL query information.
mp-wp_genesis 7 *
mp-wp_genesis 8 * @link http://codex.wordpress.org/The_Loop More information on The Loop.
mp-wp_genesis 9 *
mp-wp_genesis 10 * @package WordPress
mp-wp_genesis 11 * @subpackage Query
mp-wp_genesis 12 */
mp-wp_genesis 13
mp-wp_genesis 14 /**
mp-wp_genesis 15 * Retrieve variable in the WP_Query class.
mp-wp_genesis 16 *
mp-wp_genesis 17 * @see WP_Query::get()
mp-wp_genesis 18 * @since 1.5.0
mp-wp_genesis 19 * @uses $wp_query
mp-wp_genesis 20 *
mp-wp_genesis 21 * @param string $var The variable key to retrieve.
mp-wp_genesis 22 * @return mixed
mp-wp_genesis 23 */
mp-wp_genesis 24 function get_query_var($var) {
mp-wp_genesis 25 global $wp_query;
mp-wp_genesis 26
mp-wp_genesis 27 return $wp_query->get($var);
mp-wp_genesis 28 }
mp-wp_genesis 29
mp-wp_genesis 30 /**
mp-wp_genesis 31 * Set query variable.
mp-wp_genesis 32 *
mp-wp_genesis 33 * @see WP_Query::set()
mp-wp_genesis 34 * @since 2.2.0
mp-wp_genesis 35 * @uses $wp_query
mp-wp_genesis 36 *
mp-wp_genesis 37 * @param string $var Query variable key.
mp-wp_genesis 38 * @param mixed $value
mp-wp_genesis 39 * @return null
mp-wp_genesis 40 */
mp-wp_genesis 41 function set_query_var($var, $value) {
mp-wp_genesis 42 global $wp_query;
mp-wp_genesis 43
mp-wp_genesis 44 return $wp_query->set($var, $value);
mp-wp_genesis 45 }
mp-wp_genesis 46
mp-wp_genesis 47 /**
mp-wp_genesis 48 * Setup The Loop with query parameters.
mp-wp_genesis 49 *
mp-wp_genesis 50 * This will override the current WordPress Loop and shouldn't be used more than
mp-wp_genesis 51 * once. This must not be used within the WordPress Loop.
mp-wp_genesis 52 *
mp-wp_genesis 53 * @since 1.5.0
mp-wp_genesis 54 * @uses $wp_query
mp-wp_genesis 55 *
mp-wp_genesis 56 * @param string $query
mp-wp_genesis 57 * @return array List of posts
mp-wp_genesis 58 */
mp-wp_genesis 59 function &query_posts($query) {
mp-wp_genesis 60 unset($GLOBALS['wp_query']);
mp-wp_genesis 61 $GLOBALS['wp_query'] = new WP_Query();
mp-wp_genesis 62 return $GLOBALS['wp_query']->query($query);
mp-wp_genesis 63 }
mp-wp_genesis 64
mp-wp_genesis 65 /**
mp-wp_genesis 66 * Destroy the previous query and setup a new query.
mp-wp_genesis 67 *
mp-wp_genesis 68 * This should be used after {@link query_posts()} and before another {@link
mp-wp_genesis 69 * query_posts()}. This will remove obscure bugs that occur when the previous
mp-wp_genesis 70 * wp_query object is not destroyed properly before another is setup.
mp-wp_genesis 71 *
mp-wp_genesis 72 * @since 2.3.0
mp-wp_genesis 73 * @uses $wp_query
mp-wp_genesis 74 */
mp-wp_genesis 75 function wp_reset_query() {
mp-wp_genesis 76 unset($GLOBALS['wp_query']);
mp-wp_genesis 77 $GLOBALS['wp_query'] =& $GLOBALS['wp_the_query'];
mp-wp_genesis 78 global $wp_query;
mp-wp_genesis 79 if ( !empty($wp_query->post) ) {
mp-wp_genesis 80 $GLOBALS['post'] = $wp_query->post;
mp-wp_genesis 81 setup_postdata($wp_query->post);
mp-wp_genesis 82 }
mp-wp_genesis 83 }
mp-wp_genesis 84
mp-wp_genesis 85 /*
mp-wp_genesis 86 * Query type checks.
mp-wp_genesis 87 */
mp-wp_genesis 88
mp-wp_genesis 89 /**
mp-wp_genesis 90 * Whether the current request is in WordPress admin Panel
mp-wp_genesis 91 *
mp-wp_genesis 92 * Does not inform on whether the user is an admin! Use capability checks to
mp-wp_genesis 93 * tell if the user should be accessing a section or not.
mp-wp_genesis 94 *
mp-wp_genesis 95 * @since 1.5.1
mp-wp_genesis 96 *
mp-wp_genesis 97 * @return bool True if inside WordPress administration pages.
mp-wp_genesis 98 */
mp-wp_genesis 99 function is_admin () {
mp-wp_genesis 100 if ( defined('WP_ADMIN') )
mp-wp_genesis 101 return WP_ADMIN;
mp-wp_genesis 102 return false;
mp-wp_genesis 103 }
mp-wp_genesis 104
mp-wp_genesis 105 /**
mp-wp_genesis 106 * Is query requesting an archive page.
mp-wp_genesis 107 *
mp-wp_genesis 108 * @since 1.5.0
mp-wp_genesis 109 * @uses $wp_query
mp-wp_genesis 110 *
mp-wp_genesis 111 * @return bool True if page is archive.
mp-wp_genesis 112 */
mp-wp_genesis 113 function is_archive () {
mp-wp_genesis 114 global $wp_query;
mp-wp_genesis 115
mp-wp_genesis 116 return $wp_query->is_archive;
mp-wp_genesis 117 }
mp-wp_genesis 118
mp-wp_genesis 119 /**
mp-wp_genesis 120 * Is query requesting an attachment page.
mp-wp_genesis 121 *
mp-wp_genesis 122 * @since 2.0.0
mp-wp_genesis 123 * @uses $wp_query
mp-wp_genesis 124 *
mp-wp_genesis 125 * @return bool True if page is attachment.
mp-wp_genesis 126 */
mp-wp_genesis 127 function is_attachment () {
mp-wp_genesis 128 global $wp_query;
mp-wp_genesis 129
mp-wp_genesis 130 return $wp_query->is_attachment;
mp-wp_genesis 131 }
mp-wp_genesis 132
mp-wp_genesis 133 /**
mp-wp_genesis 134 * Is query requesting an author page.
mp-wp_genesis 135 *
mp-wp_genesis 136 * If the $author parameter is specified then the check will be expanded to
mp-wp_genesis 137 * include whether the queried author matches the one given in the parameter.
mp-wp_genesis 138 * You can match against integers and against strings.
mp-wp_genesis 139 *
mp-wp_genesis 140 * If matching against an integer, the ID should be used of the author for the
mp-wp_genesis 141 * test. If the $author is an ID and matches the author page user ID, then
mp-wp_genesis 142 * 'true' will be returned.
mp-wp_genesis 143 *
mp-wp_genesis 144 * If matching against strings, then the test will be matched against both the
mp-wp_genesis 145 * nickname and user nicename and will return true on success.
mp-wp_genesis 146 *
mp-wp_genesis 147 * @since 1.5.0
mp-wp_genesis 148 * @uses $wp_query
mp-wp_genesis 149 *
mp-wp_genesis 150 * @param string|int $author Optional. Is current page this author.
mp-wp_genesis 151 * @return bool True if page is author or $author (if set).
mp-wp_genesis 152 */
mp-wp_genesis 153 function is_author ($author = '') {
mp-wp_genesis 154 global $wp_query;
mp-wp_genesis 155
mp-wp_genesis 156 if ( !$wp_query->is_author )
mp-wp_genesis 157 return false;
mp-wp_genesis 158
mp-wp_genesis 159 if ( empty($author) )
mp-wp_genesis 160 return true;
mp-wp_genesis 161
mp-wp_genesis 162 $author_obj = $wp_query->get_queried_object();
mp-wp_genesis 163
mp-wp_genesis 164 $author = (array) $author;
mp-wp_genesis 165
mp-wp_genesis 166 if ( in_array( $author_obj->ID, $author ) )
mp-wp_genesis 167 return true;
mp-wp_genesis 168 elseif ( in_array( $author_obj->nickname, $author ) )
mp-wp_genesis 169 return true;
mp-wp_genesis 170 elseif ( in_array( $author_obj->user_nicename, $author ) )
mp-wp_genesis 171 return true;
mp-wp_genesis 172
mp-wp_genesis 173 return false;
mp-wp_genesis 174 }
mp-wp_genesis 175
mp-wp_genesis 176 /**
mp-wp_genesis 177 * Whether current page query contains a category name or given category name.
mp-wp_genesis 178 *
mp-wp_genesis 179 * The category list can contain category IDs, names, or category slugs. If any
mp-wp_genesis 180 * of them are part of the query, then it will return true.
mp-wp_genesis 181 *
mp-wp_genesis 182 * @since 1.5.0
mp-wp_genesis 183 * @uses $wp_query
mp-wp_genesis 184 *
mp-wp_genesis 185 * @param string|array $category Optional.
mp-wp_genesis 186 * @return bool
mp-wp_genesis 187 */
mp-wp_genesis 188 function is_category ($category = '') {
mp-wp_genesis 189 global $wp_query;
mp-wp_genesis 190
mp-wp_genesis 191 if ( !$wp_query->is_category )
mp-wp_genesis 192 return false;
mp-wp_genesis 193
mp-wp_genesis 194 if ( empty($category) )
mp-wp_genesis 195 return true;
mp-wp_genesis 196
mp-wp_genesis 197 $cat_obj = $wp_query->get_queried_object();
mp-wp_genesis 198
mp-wp_genesis 199 $category = (array) $category;
mp-wp_genesis 200
mp-wp_genesis 201 if ( in_array( $cat_obj->term_id, $category ) )
mp-wp_genesis 202 return true;
mp-wp_genesis 203 elseif ( in_array( $cat_obj->name, $category ) )
mp-wp_genesis 204 return true;
mp-wp_genesis 205 elseif ( in_array( $cat_obj->slug, $category ) )
mp-wp_genesis 206 return true;
mp-wp_genesis 207
mp-wp_genesis 208 return false;
mp-wp_genesis 209 }
mp-wp_genesis 210
mp-wp_genesis 211 /**
mp-wp_genesis 212 * Whether the current page query has the given tag slug or contains tag.
mp-wp_genesis 213 *
mp-wp_genesis 214 * @since 2.3.0
mp-wp_genesis 215 * @uses $wp_query
mp-wp_genesis 216 *
mp-wp_genesis 217 * @param string|array $slug Optional. Single tag or list of tags to check for.
mp-wp_genesis 218 * @return bool
mp-wp_genesis 219 */
mp-wp_genesis 220 function is_tag( $slug = '' ) {
mp-wp_genesis 221 global $wp_query;
mp-wp_genesis 222
mp-wp_genesis 223 if ( !$wp_query->is_tag )
mp-wp_genesis 224 return false;
mp-wp_genesis 225
mp-wp_genesis 226 if ( empty( $slug ) )
mp-wp_genesis 227 return true;
mp-wp_genesis 228
mp-wp_genesis 229 $tag_obj = $wp_query->get_queried_object();
mp-wp_genesis 230
mp-wp_genesis 231 $slug = (array) $slug;
mp-wp_genesis 232
mp-wp_genesis 233 if ( in_array( $tag_obj->slug, $slug ) )
mp-wp_genesis 234 return true;
mp-wp_genesis 235
mp-wp_genesis 236 return false;
mp-wp_genesis 237 }
mp-wp_genesis 238
mp-wp_genesis 239 /**
mp-wp_genesis 240 * Whether the current page query has the given taxonomy slug or contains taxonomy.
mp-wp_genesis 241 *
mp-wp_genesis 242 * @since 2.5.0
mp-wp_genesis 243 * @uses $wp_query
mp-wp_genesis 244 *
mp-wp_genesis 245 * @param string|array $slug Optional. Slug or slugs to check in current query.
mp-wp_genesis 246 * @return bool
mp-wp_genesis 247 */
mp-wp_genesis 248 function is_tax( $slug = '' ) {
mp-wp_genesis 249 global $wp_query;
mp-wp_genesis 250
mp-wp_genesis 251 if ( !$wp_query->is_tax )
mp-wp_genesis 252 return false;
mp-wp_genesis 253
mp-wp_genesis 254 if ( empty($slug) )
mp-wp_genesis 255 return true;
mp-wp_genesis 256
mp-wp_genesis 257 $term = $wp_query->get_queried_object();
mp-wp_genesis 258
mp-wp_genesis 259 $slug = (array) $slug;
mp-wp_genesis 260
mp-wp_genesis 261 if ( in_array( $term->slug, $slug ) )
mp-wp_genesis 262 return true;
mp-wp_genesis 263
mp-wp_genesis 264 return false;
mp-wp_genesis 265 }
mp-wp_genesis 266
mp-wp_genesis 267 /**
mp-wp_genesis 268 * Whether the current URL is within the comments popup window.
mp-wp_genesis 269 *
mp-wp_genesis 270 * @since 1.5.0
mp-wp_genesis 271 * @uses $wp_query
mp-wp_genesis 272 *
mp-wp_genesis 273 * @return bool
mp-wp_genesis 274 */
mp-wp_genesis 275 function is_comments_popup () {
mp-wp_genesis 276 global $wp_query;
mp-wp_genesis 277
mp-wp_genesis 278 return $wp_query->is_comments_popup;
mp-wp_genesis 279 }
mp-wp_genesis 280
mp-wp_genesis 281 /**
mp-wp_genesis 282 * Whether current URL is based on a date.
mp-wp_genesis 283 *
mp-wp_genesis 284 * @since 1.5.0
mp-wp_genesis 285 * @uses $wp_query
mp-wp_genesis 286 *
mp-wp_genesis 287 * @return bool
mp-wp_genesis 288 */
mp-wp_genesis 289 function is_date () {
mp-wp_genesis 290 global $wp_query;
mp-wp_genesis 291
mp-wp_genesis 292 return $wp_query->is_date;
mp-wp_genesis 293 }
mp-wp_genesis 294
mp-wp_genesis 295 /**
mp-wp_genesis 296 * Whether current blog URL contains a day.
mp-wp_genesis 297 *
mp-wp_genesis 298 * @since 1.5.0
mp-wp_genesis 299 * @uses $wp_query
mp-wp_genesis 300 *
mp-wp_genesis 301 * @return bool
mp-wp_genesis 302 */
mp-wp_genesis 303 function is_day () {
mp-wp_genesis 304 global $wp_query;
mp-wp_genesis 305
mp-wp_genesis 306 return $wp_query->is_day;
mp-wp_genesis 307 }
mp-wp_genesis 308
mp-wp_genesis 309 /**
mp-wp_genesis 310 * Whether current page query is feed URL.
mp-wp_genesis 311 *
mp-wp_genesis 312 * @since 1.5.0
mp-wp_genesis 313 * @uses $wp_query
mp-wp_genesis 314 *
mp-wp_genesis 315 * @return bool
mp-wp_genesis 316 */
mp-wp_genesis 317 function is_feed () {
mp-wp_genesis 318 global $wp_query;
mp-wp_genesis 319
mp-wp_genesis 320 return $wp_query->is_feed;
mp-wp_genesis 321 }
mp-wp_genesis 322
mp-wp_genesis 323 /**
mp-wp_genesis 324 * Whether current page query is the front of the site.
mp-wp_genesis 325 *
mp-wp_genesis 326 * @since 2.5.0
mp-wp_genesis 327 * @uses is_home()
mp-wp_genesis 328 * @uses get_option()
mp-wp_genesis 329 *
mp-wp_genesis 330 * @return bool True, if front of site.
mp-wp_genesis 331 */
mp-wp_genesis 332 function is_front_page () {
mp-wp_genesis 333 // most likely case
mp-wp_genesis 334 if ( 'posts' == get_option('show_on_front') && is_home() )
mp-wp_genesis 335 return true;
mp-wp_genesis 336 elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') && is_page(get_option('page_on_front')) )
mp-wp_genesis 337 return true;
mp-wp_genesis 338 else
mp-wp_genesis 339 return false;
mp-wp_genesis 340 }
mp-wp_genesis 341
mp-wp_genesis 342 /**
mp-wp_genesis 343 * Whether current page view is the blog homepage.
mp-wp_genesis 344 *
mp-wp_genesis 345 * @since 1.5.0
mp-wp_genesis 346 * @uses $wp_query
mp-wp_genesis 347 *
mp-wp_genesis 348 * @return bool True if blog view homepage.
mp-wp_genesis 349 */
mp-wp_genesis 350 function is_home () {
mp-wp_genesis 351 global $wp_query;
mp-wp_genesis 352
mp-wp_genesis 353 return $wp_query->is_home;
mp-wp_genesis 354 }
mp-wp_genesis 355
mp-wp_genesis 356 /**
mp-wp_genesis 357 * Whether current page query contains a month.
mp-wp_genesis 358 *
mp-wp_genesis 359 * @since 1.5.0
mp-wp_genesis 360 * @uses $wp_query
mp-wp_genesis 361 *
mp-wp_genesis 362 * @return bool
mp-wp_genesis 363 */
mp-wp_genesis 364 function is_month () {
mp-wp_genesis 365 global $wp_query;
mp-wp_genesis 366
mp-wp_genesis 367 return $wp_query->is_month;
mp-wp_genesis 368 }
mp-wp_genesis 369
mp-wp_genesis 370 /**
mp-wp_genesis 371 * Whether query is page or contains given page(s).
mp-wp_genesis 372 *
mp-wp_genesis 373 * Calls the function without any parameters will only test whether the current
mp-wp_genesis 374 * query is of the page type. Either a list or a single item can be tested
mp-wp_genesis 375 * against for whether the query is a page and also is the value or one of the
mp-wp_genesis 376 * values in the page parameter.
mp-wp_genesis 377 *
mp-wp_genesis 378 * The parameter can contain the page ID, page title, or page name. The
mp-wp_genesis 379 * parameter can also be an array of those three values.
mp-wp_genesis 380 *
mp-wp_genesis 381 * @since 1.5.0
mp-wp_genesis 382 * @uses $wp_query
mp-wp_genesis 383 *
mp-wp_genesis 384 * @param mixed $page Either page or list of pages to test against.
mp-wp_genesis 385 * @return bool
mp-wp_genesis 386 */
mp-wp_genesis 387 function is_page ($page = '') {
mp-wp_genesis 388 global $wp_query;
mp-wp_genesis 389
mp-wp_genesis 390 if ( !$wp_query->is_page )
mp-wp_genesis 391 return false;
mp-wp_genesis 392
mp-wp_genesis 393 if ( empty($page) )
mp-wp_genesis 394 return true;
mp-wp_genesis 395
mp-wp_genesis 396 $page_obj = $wp_query->get_queried_object();
mp-wp_genesis 397
mp-wp_genesis 398 $page = (array) $page;
mp-wp_genesis 399
mp-wp_genesis 400 if ( in_array( $page_obj->ID, $page ) )
mp-wp_genesis 401 return true;
mp-wp_genesis 402 elseif ( in_array( $page_obj->post_title, $page ) )
mp-wp_genesis 403 return true;
mp-wp_genesis 404 else if ( in_array( $page_obj->post_name, $page ) )
mp-wp_genesis 405 return true;
mp-wp_genesis 406
mp-wp_genesis 407 return false;
mp-wp_genesis 408 }
mp-wp_genesis 409
mp-wp_genesis 410 /**
mp-wp_genesis 411 * Whether query contains multiple pages for the results.
mp-wp_genesis 412 *
mp-wp_genesis 413 * @since 1.5.0
mp-wp_genesis 414 * @uses $wp_query
mp-wp_genesis 415 *
mp-wp_genesis 416 * @return bool
mp-wp_genesis 417 */
mp-wp_genesis 418 function is_paged () {
mp-wp_genesis 419 global $wp_query;
mp-wp_genesis 420
mp-wp_genesis 421 return $wp_query->is_paged;
mp-wp_genesis 422 }
mp-wp_genesis 423
mp-wp_genesis 424 /**
mp-wp_genesis 425 * Whether the current page was created by a plugin.
mp-wp_genesis 426 *
mp-wp_genesis 427 * The plugin can set this by using the global $plugin_page and setting it to
mp-wp_genesis 428 * true.
mp-wp_genesis 429 *
mp-wp_genesis 430 * @since 1.5.0
mp-wp_genesis 431 * @global bool $plugin_page Used by plugins to tell the query that current is a plugin page.
mp-wp_genesis 432 *
mp-wp_genesis 433 * @return bool
mp-wp_genesis 434 */
mp-wp_genesis 435 function is_plugin_page() {
mp-wp_genesis 436 global $plugin_page;
mp-wp_genesis 437
mp-wp_genesis 438 if ( isset($plugin_page) )
mp-wp_genesis 439 return true;
mp-wp_genesis 440
mp-wp_genesis 441 return false;
mp-wp_genesis 442 }
mp-wp_genesis 443
mp-wp_genesis 444 /**
mp-wp_genesis 445 * Whether the current query is preview of post or page.
mp-wp_genesis 446 *
mp-wp_genesis 447 * @since 2.0.0
mp-wp_genesis 448 * @uses $wp_query
mp-wp_genesis 449 *
mp-wp_genesis 450 * @return bool
mp-wp_genesis 451 */
mp-wp_genesis 452 function is_preview() {
mp-wp_genesis 453 global $wp_query;
mp-wp_genesis 454
mp-wp_genesis 455 return $wp_query->is_preview;
mp-wp_genesis 456 }
mp-wp_genesis 457
mp-wp_genesis 458 /**
mp-wp_genesis 459 * Whether the current query post is robots.
mp-wp_genesis 460 *
mp-wp_genesis 461 * @since 2.1.0
mp-wp_genesis 462 * @uses $wp_query
mp-wp_genesis 463 *
mp-wp_genesis 464 * @return bool
mp-wp_genesis 465 */
mp-wp_genesis 466 function is_robots() {
mp-wp_genesis 467 global $wp_query;
mp-wp_genesis 468
mp-wp_genesis 469 return $wp_query->is_robots;
mp-wp_genesis 470 }
mp-wp_genesis 471
mp-wp_genesis 472 /**
mp-wp_genesis 473 * Whether current query is the result of a user search.
mp-wp_genesis 474 *
mp-wp_genesis 475 * @since 1.5.0
mp-wp_genesis 476 * @uses $wp_query
mp-wp_genesis 477 *
mp-wp_genesis 478 * @return bool
mp-wp_genesis 479 */
mp-wp_genesis 480 function is_search () {
mp-wp_genesis 481 global $wp_query;
mp-wp_genesis 482
mp-wp_genesis 483 return $wp_query->is_search;
mp-wp_genesis 484 }
mp-wp_genesis 485
mp-wp_genesis 486 /**
mp-wp_genesis 487 * Whether the current page query is single page.
mp-wp_genesis 488 *
mp-wp_genesis 489 * The parameter can contain the post ID, post title, or post name. The
mp-wp_genesis 490 * parameter can also be an array of those three values.
mp-wp_genesis 491 *
mp-wp_genesis 492 * This applies to other post types, attachments, pages, posts. Just means that
mp-wp_genesis 493 * the current query has only a single object.
mp-wp_genesis 494 *
mp-wp_genesis 495 * @since 1.5.0
mp-wp_genesis 496 * @uses $wp_query
mp-wp_genesis 497 *
mp-wp_genesis 498 * @param mixed $post Either post or list of posts to test against.
mp-wp_genesis 499 * @return bool
mp-wp_genesis 500 */
mp-wp_genesis 501 function is_single ($post = '') {
mp-wp_genesis 502 global $wp_query;
mp-wp_genesis 503
mp-wp_genesis 504 if ( !$wp_query->is_single )
mp-wp_genesis 505 return false;
mp-wp_genesis 506
mp-wp_genesis 507 if ( empty( $post) )
mp-wp_genesis 508 return true;
mp-wp_genesis 509
mp-wp_genesis 510 $post_obj = $wp_query->get_queried_object();
mp-wp_genesis 511
mp-wp_genesis 512 $post = (array) $post;
mp-wp_genesis 513
mp-wp_genesis 514 if ( in_array( $post_obj->ID, $post ) )
mp-wp_genesis 515 return true;
mp-wp_genesis 516 elseif ( in_array( $post_obj->post_title, $post ) )
mp-wp_genesis 517 return true;
mp-wp_genesis 518 elseif ( in_array( $post_obj->post_name, $post ) )
mp-wp_genesis 519 return true;
mp-wp_genesis 520
mp-wp_genesis 521 return false;
mp-wp_genesis 522 }
mp-wp_genesis 523
mp-wp_genesis 524 /**
mp-wp_genesis 525 * Whether is single post, is a page, or is an attachment.
mp-wp_genesis 526 *
mp-wp_genesis 527 * @since 1.5.0
mp-wp_genesis 528 * @uses $wp_query
mp-wp_genesis 529 *
mp-wp_genesis 530 * @return bool
mp-wp_genesis 531 */
mp-wp_genesis 532 function is_singular() {
mp-wp_genesis 533 global $wp_query;
mp-wp_genesis 534
mp-wp_genesis 535 return $wp_query->is_singular;
mp-wp_genesis 536 }
mp-wp_genesis 537
mp-wp_genesis 538 /**
mp-wp_genesis 539 * Whether the query contains a time.
mp-wp_genesis 540 *
mp-wp_genesis 541 * @since 1.5.0
mp-wp_genesis 542 * @uses $wp_query
mp-wp_genesis 543 *
mp-wp_genesis 544 * @return bool
mp-wp_genesis 545 */
mp-wp_genesis 546 function is_time () {
mp-wp_genesis 547 global $wp_query;
mp-wp_genesis 548
mp-wp_genesis 549 return $wp_query->is_time;
mp-wp_genesis 550 }
mp-wp_genesis 551
mp-wp_genesis 552 /**
mp-wp_genesis 553 * Whether the query is a trackback.
mp-wp_genesis 554 *
mp-wp_genesis 555 * @since 1.5.0
mp-wp_genesis 556 * @uses $wp_query
mp-wp_genesis 557 *
mp-wp_genesis 558 * @return bool
mp-wp_genesis 559 */
mp-wp_genesis 560 function is_trackback () {
mp-wp_genesis 561 global $wp_query;
mp-wp_genesis 562
mp-wp_genesis 563 return $wp_query->is_trackback;
mp-wp_genesis 564 }
mp-wp_genesis 565
mp-wp_genesis 566 /**
mp-wp_genesis 567 * Whether the query contains a year.
mp-wp_genesis 568 *
mp-wp_genesis 569 * @since 1.5.0
mp-wp_genesis 570 * @uses $wp_query
mp-wp_genesis 571 *
mp-wp_genesis 572 * @return bool
mp-wp_genesis 573 */
mp-wp_genesis 574 function is_year () {
mp-wp_genesis 575 global $wp_query;
mp-wp_genesis 576
mp-wp_genesis 577 return $wp_query->is_year;
mp-wp_genesis 578 }
mp-wp_genesis 579
mp-wp_genesis 580 /**
mp-wp_genesis 581 * Whether current page query is a 404 and no results for WordPress query.
mp-wp_genesis 582 *
mp-wp_genesis 583 * @since 1.5.0
mp-wp_genesis 584 * @uses $wp_query
mp-wp_genesis 585 *
mp-wp_genesis 586 * @return bool True, if nothing is found matching WordPress Query.
mp-wp_genesis 587 */
mp-wp_genesis 588 function is_404 () {
mp-wp_genesis 589 global $wp_query;
mp-wp_genesis 590
mp-wp_genesis 591 return $wp_query->is_404;
mp-wp_genesis 592 }
mp-wp_genesis 593
mp-wp_genesis 594 /*
mp-wp_genesis 595 * The Loop. Post loop control.
mp-wp_genesis 596 */
mp-wp_genesis 597
mp-wp_genesis 598 /**
mp-wp_genesis 599 * Whether current WordPress query has results to loop over.
mp-wp_genesis 600 *
mp-wp_genesis 601 * @see WP_Query::have_posts()
mp-wp_genesis 602 * @since 1.5.0
mp-wp_genesis 603 * @uses $wp_query
mp-wp_genesis 604 *
mp-wp_genesis 605 * @return bool
mp-wp_genesis 606 */
mp-wp_genesis 607 function have_posts() {
mp-wp_genesis 608 global $wp_query;
mp-wp_genesis 609
mp-wp_genesis 610 return $wp_query->have_posts();
mp-wp_genesis 611 }
mp-wp_genesis 612
mp-wp_genesis 613 /**
mp-wp_genesis 614 * Whether the caller is in the Loop.
mp-wp_genesis 615 *
mp-wp_genesis 616 * @since 2.0.0
mp-wp_genesis 617 * @uses $wp_query
mp-wp_genesis 618 *
mp-wp_genesis 619 * @return bool True if caller is within loop, false if loop hasn't started or ended.
mp-wp_genesis 620 */
mp-wp_genesis 621 function in_the_loop() {
mp-wp_genesis 622 global $wp_query;
mp-wp_genesis 623
mp-wp_genesis 624 return $wp_query->in_the_loop;
mp-wp_genesis 625 }
mp-wp_genesis 626
mp-wp_genesis 627 /**
mp-wp_genesis 628 * Rewind the loop posts.
mp-wp_genesis 629 *
mp-wp_genesis 630 * @see WP_Query::rewind_posts()
mp-wp_genesis 631 * @since 1.5.0
mp-wp_genesis 632 * @uses $wp_query
mp-wp_genesis 633 *
mp-wp_genesis 634 * @return null
mp-wp_genesis 635 */
mp-wp_genesis 636 function rewind_posts() {
mp-wp_genesis 637 global $wp_query;
mp-wp_genesis 638
mp-wp_genesis 639 return $wp_query->rewind_posts();
mp-wp_genesis 640 }
mp-wp_genesis 641
mp-wp_genesis 642 /**
mp-wp_genesis 643 * Iterate the post index in the loop.
mp-wp_genesis 644 *
mp-wp_genesis 645 * @see WP_Query::the_post()
mp-wp_genesis 646 * @since 1.5.0
mp-wp_genesis 647 * @uses $wp_query
mp-wp_genesis 648 */
mp-wp_genesis 649 function the_post() {
mp-wp_genesis 650 global $wp_query;
mp-wp_genesis 651
mp-wp_genesis 652 $wp_query->the_post();
mp-wp_genesis 653 }
mp-wp_genesis 654
mp-wp_genesis 655 /*
mp-wp_genesis 656 * Comments loop.
mp-wp_genesis 657 */
mp-wp_genesis 658
mp-wp_genesis 659 /**
mp-wp_genesis 660 * Whether there are comments to loop over.
mp-wp_genesis 661 *
mp-wp_genesis 662 * @see WP_Query::have_comments()
mp-wp_genesis 663 * @since 2.2.0
mp-wp_genesis 664 * @uses $wp_query
mp-wp_genesis 665 *
mp-wp_genesis 666 * @return bool
mp-wp_genesis 667 */
mp-wp_genesis 668 function have_comments() {
mp-wp_genesis 669 global $wp_query;
mp-wp_genesis 670 return $wp_query->have_comments();
mp-wp_genesis 671 }
mp-wp_genesis 672
mp-wp_genesis 673 /**
mp-wp_genesis 674 * Iterate comment index in the comment loop.
mp-wp_genesis 675 *
mp-wp_genesis 676 * @see WP_Query::the_comment()
mp-wp_genesis 677 * @since 2.2.0
mp-wp_genesis 678 * @uses $wp_query
mp-wp_genesis 679 *
mp-wp_genesis 680 * @return object
mp-wp_genesis 681 */
mp-wp_genesis 682 function the_comment() {
mp-wp_genesis 683 global $wp_query;
mp-wp_genesis 684 return $wp_query->the_comment();
mp-wp_genesis 685 }
mp-wp_genesis 686
mp-wp_genesis 687 /*
mp-wp_genesis 688 * WP_Query
mp-wp_genesis 689 */
mp-wp_genesis 690
mp-wp_genesis 691 /**
mp-wp_genesis 692 * The WordPress Query class.
mp-wp_genesis 693 *
mp-wp_genesis 694 * @link http://codex.wordpress.org/Function_Reference/WP_Query Codex page.
mp-wp_genesis 695 *
mp-wp_genesis 696 * @since 1.5.0
mp-wp_genesis 697 */
mp-wp_genesis 698 class WP_Query {
mp-wp_genesis 699
mp-wp_genesis 700 /**
mp-wp_genesis 701 * Query string
mp-wp_genesis 702 *
mp-wp_genesis 703 * @since 1.5.0
mp-wp_genesis 704 * @access public
mp-wp_genesis 705 * @var string
mp-wp_genesis 706 */
mp-wp_genesis 707 var $query;
mp-wp_genesis 708
mp-wp_genesis 709 /**
mp-wp_genesis 710 * Query search variables set by the user.
mp-wp_genesis 711 *
mp-wp_genesis 712 * @since 1.5.0
mp-wp_genesis 713 * @access public
mp-wp_genesis 714 * @var array
mp-wp_genesis 715 */
mp-wp_genesis 716 var $query_vars = array();
mp-wp_genesis 717
mp-wp_genesis 718 /**
mp-wp_genesis 719 * Holds the data for a single object that is queried.
mp-wp_genesis 720 *
mp-wp_genesis 721 * Holds the contents of a post, page, category, attachment.
mp-wp_genesis 722 *
mp-wp_genesis 723 * @since 1.5.0
mp-wp_genesis 724 * @access public
mp-wp_genesis 725 * @var object|array
mp-wp_genesis 726 */
mp-wp_genesis 727 var $queried_object;
mp-wp_genesis 728
mp-wp_genesis 729 /**
mp-wp_genesis 730 * The ID of the queried object.
mp-wp_genesis 731 *
mp-wp_genesis 732 * @since 1.5.0
mp-wp_genesis 733 * @access public
mp-wp_genesis 734 * @var int
mp-wp_genesis 735 */
mp-wp_genesis 736 var $queried_object_id;
mp-wp_genesis 737
mp-wp_genesis 738 /**
mp-wp_genesis 739 * Get post database query.
mp-wp_genesis 740 *
mp-wp_genesis 741 * @since 2.0.1
mp-wp_genesis 742 * @access public
mp-wp_genesis 743 * @var string
mp-wp_genesis 744 */
mp-wp_genesis 745 var $request;
mp-wp_genesis 746
mp-wp_genesis 747 /**
mp-wp_genesis 748 * List of posts.
mp-wp_genesis 749 *
mp-wp_genesis 750 * @since 1.5.0
mp-wp_genesis 751 * @access public
mp-wp_genesis 752 * @var array
mp-wp_genesis 753 */
mp-wp_genesis 754 var $posts;
mp-wp_genesis 755
mp-wp_genesis 756 /**
mp-wp_genesis 757 * The amount of posts for the current query.
mp-wp_genesis 758 *
mp-wp_genesis 759 * @since 1.5.0
mp-wp_genesis 760 * @access public
mp-wp_genesis 761 * @var int
mp-wp_genesis 762 */
mp-wp_genesis 763 var $post_count = 0;
mp-wp_genesis 764
mp-wp_genesis 765 /**
mp-wp_genesis 766 * Index of the current item in the loop.
mp-wp_genesis 767 *
mp-wp_genesis 768 * @since 1.5.0
mp-wp_genesis 769 * @access public
mp-wp_genesis 770 * @var int
mp-wp_genesis 771 */
mp-wp_genesis 772 var $current_post = -1;
mp-wp_genesis 773
mp-wp_genesis 774 /**
mp-wp_genesis 775 * Whether the loop has started and the caller is in the loop.
mp-wp_genesis 776 *
mp-wp_genesis 777 * @since 2.0.0
mp-wp_genesis 778 * @access public
mp-wp_genesis 779 * @var bool
mp-wp_genesis 780 */
mp-wp_genesis 781 var $in_the_loop = false;
mp-wp_genesis 782
mp-wp_genesis 783 /**
mp-wp_genesis 784 * The current post ID.
mp-wp_genesis 785 *
mp-wp_genesis 786 * @since 1.5.0
mp-wp_genesis 787 * @access public
mp-wp_genesis 788 * @var int
mp-wp_genesis 789 */
mp-wp_genesis 790 var $post;
mp-wp_genesis 791
mp-wp_genesis 792 /**
mp-wp_genesis 793 * The list of comments for current post.
mp-wp_genesis 794 *
mp-wp_genesis 795 * @since 2.2.0
mp-wp_genesis 796 * @access public
mp-wp_genesis 797 * @var array
mp-wp_genesis 798 */
mp-wp_genesis 799 var $comments;
mp-wp_genesis 800
mp-wp_genesis 801 /**
mp-wp_genesis 802 * The amount of comments for the posts.
mp-wp_genesis 803 *
mp-wp_genesis 804 * @since 2.2.0
mp-wp_genesis 805 * @access public
mp-wp_genesis 806 * @var int
mp-wp_genesis 807 */
mp-wp_genesis 808 var $comment_count = 0;
mp-wp_genesis 809
mp-wp_genesis 810 /**
mp-wp_genesis 811 * The index of the comment in the comment loop.
mp-wp_genesis 812 *
mp-wp_genesis 813 * @since 2.2.0
mp-wp_genesis 814 * @access public
mp-wp_genesis 815 * @var int
mp-wp_genesis 816 */
mp-wp_genesis 817 var $current_comment = -1;
mp-wp_genesis 818
mp-wp_genesis 819 /**
mp-wp_genesis 820 * Current comment ID.
mp-wp_genesis 821 *
mp-wp_genesis 822 * @since 2.2.0
mp-wp_genesis 823 * @access public
mp-wp_genesis 824 * @var int
mp-wp_genesis 825 */
mp-wp_genesis 826 var $comment;
mp-wp_genesis 827
mp-wp_genesis 828 /**
mp-wp_genesis 829 * Amount of posts if limit clause was not used.
mp-wp_genesis 830 *
mp-wp_genesis 831 * @since 2.1.0
mp-wp_genesis 832 * @access public
mp-wp_genesis 833 * @var int
mp-wp_genesis 834 */
mp-wp_genesis 835 var $found_posts = 0;
mp-wp_genesis 836
mp-wp_genesis 837 /**
mp-wp_genesis 838 * The amount of pages.
mp-wp_genesis 839 *
mp-wp_genesis 840 * @since 2.1.0
mp-wp_genesis 841 * @access public
mp-wp_genesis 842 * @var int
mp-wp_genesis 843 */
mp-wp_genesis 844 var $max_num_pages = 0;
mp-wp_genesis 845
mp-wp_genesis 846 /**
mp-wp_genesis 847 * The amount of comment pages.
mp-wp_genesis 848 *
mp-wp_genesis 849 * @since 2.7.0
mp-wp_genesis 850 * @access public
mp-wp_genesis 851 * @var int
mp-wp_genesis 852 */
mp-wp_genesis 853 var $max_num_comment_pages = 0;
mp-wp_genesis 854
mp-wp_genesis 855 /**
mp-wp_genesis 856 * Set if query is single post.
mp-wp_genesis 857 *
mp-wp_genesis 858 * @since 1.5.0
mp-wp_genesis 859 * @access public
mp-wp_genesis 860 * @var bool
mp-wp_genesis 861 */
mp-wp_genesis 862 var $is_single = false;
mp-wp_genesis 863
mp-wp_genesis 864 /**
mp-wp_genesis 865 * Set if query is preview of blog.
mp-wp_genesis 866 *
mp-wp_genesis 867 * @since 2.0.0
mp-wp_genesis 868 * @access public
mp-wp_genesis 869 * @var bool
mp-wp_genesis 870 */
mp-wp_genesis 871 var $is_preview = false;
mp-wp_genesis 872
mp-wp_genesis 873 /**
mp-wp_genesis 874 * Set if query returns a page.
mp-wp_genesis 875 *
mp-wp_genesis 876 * @since 1.5.0
mp-wp_genesis 877 * @access public
mp-wp_genesis 878 * @var bool
mp-wp_genesis 879 */
mp-wp_genesis 880 var $is_page = false;
mp-wp_genesis 881
mp-wp_genesis 882 /**
mp-wp_genesis 883 * Set if query is an archive list.
mp-wp_genesis 884 *
mp-wp_genesis 885 * @since 1.5.0
mp-wp_genesis 886 * @access public
mp-wp_genesis 887 * @var bool
mp-wp_genesis 888 */
mp-wp_genesis 889 var $is_archive = false;
mp-wp_genesis 890
mp-wp_genesis 891 /**
mp-wp_genesis 892 * Set if query is part of a date.
mp-wp_genesis 893 *
mp-wp_genesis 894 * @since 1.5.0
mp-wp_genesis 895 * @access public
mp-wp_genesis 896 * @var bool
mp-wp_genesis 897 */
mp-wp_genesis 898 var $is_date = false;
mp-wp_genesis 899
mp-wp_genesis 900 /**
mp-wp_genesis 901 * Set if query contains a year.
mp-wp_genesis 902 *
mp-wp_genesis 903 * @since 1.5.0
mp-wp_genesis 904 * @access public
mp-wp_genesis 905 * @var bool
mp-wp_genesis 906 */
mp-wp_genesis 907 var $is_year = false;
mp-wp_genesis 908
mp-wp_genesis 909 /**
mp-wp_genesis 910 * Set if query contains a month.
mp-wp_genesis 911 *
mp-wp_genesis 912 * @since 1.5.0
mp-wp_genesis 913 * @access public
mp-wp_genesis 914 * @var bool
mp-wp_genesis 915 */
mp-wp_genesis 916 var $is_month = false;
mp-wp_genesis 917
mp-wp_genesis 918 /**
mp-wp_genesis 919 * Set if query contains a day.
mp-wp_genesis 920 *
mp-wp_genesis 921 * @since 1.5.0
mp-wp_genesis 922 * @access public
mp-wp_genesis 923 * @var bool
mp-wp_genesis 924 */
mp-wp_genesis 925 var $is_day = false;
mp-wp_genesis 926
mp-wp_genesis 927 /**
mp-wp_genesis 928 * Set if query contains time.
mp-wp_genesis 929 *
mp-wp_genesis 930 * @since 1.5.0
mp-wp_genesis 931 * @access public
mp-wp_genesis 932 * @var bool
mp-wp_genesis 933 */
mp-wp_genesis 934 var $is_time = false;
mp-wp_genesis 935
mp-wp_genesis 936 /**
mp-wp_genesis 937 * Set if query contains an author.
mp-wp_genesis 938 *
mp-wp_genesis 939 * @since 1.5.0
mp-wp_genesis 940 * @access public
mp-wp_genesis 941 * @var bool
mp-wp_genesis 942 */
mp-wp_genesis 943 var $is_author = false;
mp-wp_genesis 944
mp-wp_genesis 945 /**
mp-wp_genesis 946 * Set if query contains category.
mp-wp_genesis 947 *
mp-wp_genesis 948 * @since 1.5.0
mp-wp_genesis 949 * @access public
mp-wp_genesis 950 * @var bool
mp-wp_genesis 951 */
mp-wp_genesis 952 var $is_category = false;
mp-wp_genesis 953
mp-wp_genesis 954 /**
mp-wp_genesis 955 * Set if query contains tag.
mp-wp_genesis 956 *
mp-wp_genesis 957 * @since 2.3.0
mp-wp_genesis 958 * @access public
mp-wp_genesis 959 * @var bool
mp-wp_genesis 960 */
mp-wp_genesis 961 var $is_tag = false;
mp-wp_genesis 962
mp-wp_genesis 963 /**
mp-wp_genesis 964 * Set if query contains taxonomy.
mp-wp_genesis 965 *
mp-wp_genesis 966 * @since 2.5.0
mp-wp_genesis 967 * @access public
mp-wp_genesis 968 * @var bool
mp-wp_genesis 969 */
mp-wp_genesis 970 var $is_tax = false;
mp-wp_genesis 971
mp-wp_genesis 972 /**
mp-wp_genesis 973 * Set if query was part of a search result.
mp-wp_genesis 974 *
mp-wp_genesis 975 * @since 1.5.0
mp-wp_genesis 976 * @access public
mp-wp_genesis 977 * @var bool
mp-wp_genesis 978 */
mp-wp_genesis 979 var $is_search = false;
mp-wp_genesis 980
mp-wp_genesis 981 /**
mp-wp_genesis 982 * Set if query is feed display.
mp-wp_genesis 983 *
mp-wp_genesis 984 * @since 1.5.0
mp-wp_genesis 985 * @access public
mp-wp_genesis 986 * @var bool
mp-wp_genesis 987 */
mp-wp_genesis 988 var $is_feed = false;
mp-wp_genesis 989
mp-wp_genesis 990 /**
mp-wp_genesis 991 * Set if query is comment feed display.
mp-wp_genesis 992 *
mp-wp_genesis 993 * @since 2.2.0
mp-wp_genesis 994 * @access public
mp-wp_genesis 995 * @var bool
mp-wp_genesis 996 */
mp-wp_genesis 997 var $is_comment_feed = false;
mp-wp_genesis 998
mp-wp_genesis 999 /**
mp-wp_genesis 1000 * Set if query is trackback.
mp-wp_genesis 1001 *
mp-wp_genesis 1002 * @since 1.5.0
mp-wp_genesis 1003 * @access public
mp-wp_genesis 1004 * @var bool
mp-wp_genesis 1005 */
mp-wp_genesis 1006 var $is_trackback = false;
mp-wp_genesis 1007
mp-wp_genesis 1008 /**
mp-wp_genesis 1009 * Set if query is blog homepage.
mp-wp_genesis 1010 *
mp-wp_genesis 1011 * @since 1.5.0
mp-wp_genesis 1012 * @access public
mp-wp_genesis 1013 * @var bool
mp-wp_genesis 1014 */
mp-wp_genesis 1015 var $is_home = false;
mp-wp_genesis 1016
mp-wp_genesis 1017 /**
mp-wp_genesis 1018 * Set if query couldn't found anything.
mp-wp_genesis 1019 *
mp-wp_genesis 1020 * @since 1.5.0
mp-wp_genesis 1021 * @access public
mp-wp_genesis 1022 * @var bool
mp-wp_genesis 1023 */
mp-wp_genesis 1024 var $is_404 = false;
mp-wp_genesis 1025
mp-wp_genesis 1026 /**
mp-wp_genesis 1027 * Set if query is within comments popup window.
mp-wp_genesis 1028 *
mp-wp_genesis 1029 * @since 1.5.0
mp-wp_genesis 1030 * @access public
mp-wp_genesis 1031 * @var bool
mp-wp_genesis 1032 */
mp-wp_genesis 1033 var $is_comments_popup = false;
mp-wp_genesis 1034
mp-wp_genesis 1035 /**
mp-wp_genesis 1036 * Set if query is part of administration page.
mp-wp_genesis 1037 *
mp-wp_genesis 1038 * @since 1.5.0
mp-wp_genesis 1039 * @access public
mp-wp_genesis 1040 * @var bool
mp-wp_genesis 1041 */
mp-wp_genesis 1042 var $is_admin = false;
mp-wp_genesis 1043
mp-wp_genesis 1044 /**
mp-wp_genesis 1045 * Set if query is an attachment.
mp-wp_genesis 1046 *
mp-wp_genesis 1047 * @since 2.0.0
mp-wp_genesis 1048 * @access public
mp-wp_genesis 1049 * @var bool
mp-wp_genesis 1050 */
mp-wp_genesis 1051 var $is_attachment = false;
mp-wp_genesis 1052
mp-wp_genesis 1053 /**
mp-wp_genesis 1054 * Set if is single, is a page, or is an attachment.
mp-wp_genesis 1055 *
mp-wp_genesis 1056 * @since 2.1.0
mp-wp_genesis 1057 * @access public
mp-wp_genesis 1058 * @var bool
mp-wp_genesis 1059 */
mp-wp_genesis 1060 var $is_singular = false;
mp-wp_genesis 1061
mp-wp_genesis 1062 /**
mp-wp_genesis 1063 * Set if query is for robots.
mp-wp_genesis 1064 *
mp-wp_genesis 1065 * @since 2.1.0
mp-wp_genesis 1066 * @access public
mp-wp_genesis 1067 * @var bool
mp-wp_genesis 1068 */
mp-wp_genesis 1069 var $is_robots = false;
mp-wp_genesis 1070
mp-wp_genesis 1071 /**
mp-wp_genesis 1072 * Set if query contains posts.
mp-wp_genesis 1073 *
mp-wp_genesis 1074 * Basically, the homepage if the option isn't set for the static homepage.
mp-wp_genesis 1075 *
mp-wp_genesis 1076 * @since 2.1.0
mp-wp_genesis 1077 * @access public
mp-wp_genesis 1078 * @var bool
mp-wp_genesis 1079 */
mp-wp_genesis 1080 var $is_posts_page = false;
mp-wp_genesis 1081
mp-wp_genesis 1082 /**
mp-wp_genesis 1083 * Resets query flags to false.
mp-wp_genesis 1084 *
mp-wp_genesis 1085 * The query flags are what page info WordPress was able to figure out.
mp-wp_genesis 1086 *
mp-wp_genesis 1087 * @since 2.0.0
mp-wp_genesis 1088 * @access private
mp-wp_genesis 1089 */
mp-wp_genesis 1090 function init_query_flags() {
mp-wp_genesis 1091 $this->is_single = false;
mp-wp_genesis 1092 $this->is_page = false;
mp-wp_genesis 1093 $this->is_archive = false;
mp-wp_genesis 1094 $this->is_date = false;
mp-wp_genesis 1095 $this->is_year = false;
mp-wp_genesis 1096 $this->is_month = false;
mp-wp_genesis 1097 $this->is_day = false;
mp-wp_genesis 1098 $this->is_time = false;
mp-wp_genesis 1099 $this->is_author = false;
mp-wp_genesis 1100 $this->is_category = false;
mp-wp_genesis 1101 $this->is_tag = false;
mp-wp_genesis 1102 $this->is_tax = false;
mp-wp_genesis 1103 $this->is_search = false;
mp-wp_genesis 1104 $this->is_feed = false;
mp-wp_genesis 1105 $this->is_comment_feed = false;
mp-wp_genesis 1106 $this->is_trackback = false;
mp-wp_genesis 1107 $this->is_home = false;
mp-wp_genesis 1108 $this->is_404 = false;
mp-wp_genesis 1109 $this->is_paged = false;
mp-wp_genesis 1110 $this->is_admin = false;
mp-wp_genesis 1111 $this->is_attachment = false;
mp-wp_genesis 1112 $this->is_singular = false;
mp-wp_genesis 1113 $this->is_robots = false;
mp-wp_genesis 1114 $this->is_posts_page = false;
mp-wp_genesis 1115 }
mp-wp_genesis 1116
mp-wp_genesis 1117 /**
mp-wp_genesis 1118 * Initiates object properties and sets default values.
mp-wp_genesis 1119 *
mp-wp_genesis 1120 * @since 1.5.0
mp-wp_genesis 1121 * @access public
mp-wp_genesis 1122 */
mp-wp_genesis 1123 function init () {
mp-wp_genesis 1124 unset($this->posts);
mp-wp_genesis 1125 unset($this->query);
mp-wp_genesis 1126 $this->query_vars = array();
mp-wp_genesis 1127 unset($this->queried_object);
mp-wp_genesis 1128 unset($this->queried_object_id);
mp-wp_genesis 1129 $this->post_count = 0;
mp-wp_genesis 1130 $this->current_post = -1;
mp-wp_genesis 1131 $this->in_the_loop = false;
mp-wp_genesis 1132
mp-wp_genesis 1133 $this->init_query_flags();
mp-wp_genesis 1134 }
mp-wp_genesis 1135
mp-wp_genesis 1136 /**
mp-wp_genesis 1137 * Reparse the query vars.
mp-wp_genesis 1138 *
mp-wp_genesis 1139 * @since 1.5.0
mp-wp_genesis 1140 * @access public
mp-wp_genesis 1141 */
mp-wp_genesis 1142 function parse_query_vars() {
mp-wp_genesis 1143 $this->parse_query('');
mp-wp_genesis 1144 }
mp-wp_genesis 1145
mp-wp_genesis 1146 /**
mp-wp_genesis 1147 * Fills in the query variables, which do not exist within the parameter.
mp-wp_genesis 1148 *
mp-wp_genesis 1149 * @since 2.1.0
mp-wp_genesis 1150 * @access public
mp-wp_genesis 1151 *
mp-wp_genesis 1152 * @param array $array Defined query variables.
mp-wp_genesis 1153 * @return array Complete query variables with undefined ones filled in empty.
mp-wp_genesis 1154 */
mp-wp_genesis 1155 function fill_query_vars($array) {
mp-wp_genesis 1156 $keys = array(
mp-wp_genesis 1157 'error'
mp-wp_genesis 1158 , 'm'
mp-wp_genesis 1159 , 'p'
mp-wp_genesis 1160 , 'post_parent'
mp-wp_genesis 1161 , 'subpost'
mp-wp_genesis 1162 , 'subpost_id'
mp-wp_genesis 1163 , 'attachment'
mp-wp_genesis 1164 , 'attachment_id'
mp-wp_genesis 1165 , 'name'
mp-wp_genesis 1166 , 'hour'
mp-wp_genesis 1167 , 'static'
mp-wp_genesis 1168 , 'pagename'
mp-wp_genesis 1169 , 'page_id'
mp-wp_genesis 1170 , 'second'
mp-wp_genesis 1171 , 'minute'
mp-wp_genesis 1172 , 'hour'
mp-wp_genesis 1173 , 'day'
mp-wp_genesis 1174 , 'monthnum'
mp-wp_genesis 1175 , 'year'
mp-wp_genesis 1176 , 'w'
mp-wp_genesis 1177 , 'category_name'
mp-wp_genesis 1178 , 'tag'
mp-wp_genesis 1179 , 'cat'
mp-wp_genesis 1180 , 'tag_id'
mp-wp_genesis 1181 , 'author_name'
mp-wp_genesis 1182 , 'feed'
mp-wp_genesis 1183 , 'tb'
mp-wp_genesis 1184 , 'paged'
mp-wp_genesis 1185 , 'comments_popup'
mp-wp_genesis 1186 , 'meta_key'
mp-wp_genesis 1187 , 'meta_value'
mp-wp_genesis 1188 , 'preview'
mp-wp_genesis 1189 );
mp-wp_genesis 1190
mp-wp_genesis 1191 foreach ($keys as $key) {
mp-wp_genesis 1192 if ( !isset($array[$key]))
mp-wp_genesis 1193 $array[$key] = '';
mp-wp_genesis 1194 }
mp-wp_genesis 1195
mp-wp_genesis 1196 $array_keys = array('category__in', 'category__not_in', 'category__and', 'post__in', 'post__not_in',
mp-wp_genesis 1197 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and');
mp-wp_genesis 1198
mp-wp_genesis 1199 foreach ( $array_keys as $key ) {
mp-wp_genesis 1200 if ( !isset($array[$key]))
mp-wp_genesis 1201 $array[$key] = array();
mp-wp_genesis 1202 }
mp-wp_genesis 1203 return $array;
mp-wp_genesis 1204 }
mp-wp_genesis 1205
mp-wp_genesis 1206 /**
mp-wp_genesis 1207 * Parse a query string and set query type booleans.
mp-wp_genesis 1208 *
mp-wp_genesis 1209 * @since 1.5.0
mp-wp_genesis 1210 * @access public
mp-wp_genesis 1211 *
mp-wp_genesis 1212 * @param string|array $query
mp-wp_genesis 1213 */
mp-wp_genesis 1214 function parse_query ($query) {
mp-wp_genesis 1215 if ( !empty($query) || !isset($this->query) ) {
mp-wp_genesis 1216 $this->init();
mp-wp_genesis 1217 if ( is_array($query) )
mp-wp_genesis 1218 $this->query_vars = $query;
mp-wp_genesis 1219 else
mp-wp_genesis 1220 parse_str($query, $this->query_vars);
mp-wp_genesis 1221 $this->query = $query;
mp-wp_genesis 1222 }
mp-wp_genesis 1223
mp-wp_genesis 1224 $this->query_vars = $this->fill_query_vars($this->query_vars);
mp-wp_genesis 1225 $qv = &$this->query_vars;
mp-wp_genesis 1226
mp-wp_genesis 1227 if ( ! empty($qv['robots']) )
mp-wp_genesis 1228 $this->is_robots = true;
mp-wp_genesis 1229
mp-wp_genesis 1230 $qv['p'] = absint($qv['p']);
mp-wp_genesis 1231 $qv['page_id'] = absint($qv['page_id']);
mp-wp_genesis 1232 $qv['year'] = absint($qv['year']);
mp-wp_genesis 1233 $qv['monthnum'] = absint($qv['monthnum']);
mp-wp_genesis 1234 $qv['day'] = absint($qv['day']);
mp-wp_genesis 1235 $qv['w'] = absint($qv['w']);
mp-wp_genesis 1236 $qv['m'] = absint($qv['m']);
mp-wp_genesis 1237 $qv['cat'] = preg_replace( '|[^0-9,-]|', '', $qv['cat'] ); // comma separated list of positive or negative integers
mp-wp_genesis 1238 $qv['pagename'] = trim( $qv['pagename'] );
mp-wp_genesis 1239 $qv['name'] = trim( $qv['name'] );
mp-wp_genesis 1240 if ( '' !== $qv['hour'] ) $qv['hour'] = absint($qv['hour']);
mp-wp_genesis 1241 if ( '' !== $qv['minute'] ) $qv['minute'] = absint($qv['minute']);
mp-wp_genesis 1242 if ( '' !== $qv['second'] ) $qv['second'] = absint($qv['second']);
mp-wp_genesis 1243
mp-wp_genesis 1244 // Compat. Map subpost to attachment.
mp-wp_genesis 1245 if ( '' != $qv['subpost'] )
mp-wp_genesis 1246 $qv['attachment'] = $qv['subpost'];
mp-wp_genesis 1247 if ( '' != $qv['subpost_id'] )
mp-wp_genesis 1248 $qv['attachment_id'] = $qv['subpost_id'];
mp-wp_genesis 1249
mp-wp_genesis 1250 $qv['attachment_id'] = absint($qv['attachment_id']);
mp-wp_genesis 1251
mp-wp_genesis 1252 if ( ('' != $qv['attachment']) || !empty($qv['attachment_id']) ) {
mp-wp_genesis 1253 $this->is_single = true;
mp-wp_genesis 1254 $this->is_attachment = true;
mp-wp_genesis 1255 } elseif ( '' != $qv['name'] ) {
mp-wp_genesis 1256 $this->is_single = true;
mp-wp_genesis 1257 } elseif ( $qv['p'] ) {
mp-wp_genesis 1258 $this->is_single = true;
mp-wp_genesis 1259 } elseif ( ('' !== $qv['hour']) && ('' !== $qv['minute']) &&('' !== $qv['second']) && ('' != $qv['year']) && ('' != $qv['monthnum']) && ('' != $qv['day']) ) {
mp-wp_genesis 1260 // If year, month, day, hour, minute, and second are set, a single
mp-wp_genesis 1261 // post is being queried.
mp-wp_genesis 1262 $this->is_single = true;
mp-wp_genesis 1263 } elseif ( '' != $qv['static'] || '' != $qv['pagename'] || !empty($qv['page_id']) ) {
mp-wp_genesis 1264 $this->is_page = true;
mp-wp_genesis 1265 $this->is_single = false;
mp-wp_genesis 1266 } elseif ( !empty($qv['s']) ) {
mp-wp_genesis 1267 $this->is_search = true;
mp-wp_genesis 1268 } else {
mp-wp_genesis 1269 // Look for archive queries. Dates, categories, authors.
mp-wp_genesis 1270
mp-wp_genesis 1271 if ( '' !== $qv['second'] ) {
mp-wp_genesis 1272 $this->is_time = true;
mp-wp_genesis 1273 $this->is_date = true;
mp-wp_genesis 1274 }
mp-wp_genesis 1275
mp-wp_genesis 1276 if ( '' !== $qv['minute'] ) {
mp-wp_genesis 1277 $this->is_time = true;
mp-wp_genesis 1278 $this->is_date = true;
mp-wp_genesis 1279 }
mp-wp_genesis 1280
mp-wp_genesis 1281 if ( '' !== $qv['hour'] ) {
mp-wp_genesis 1282 $this->is_time = true;
mp-wp_genesis 1283 $this->is_date = true;
mp-wp_genesis 1284 }
mp-wp_genesis 1285
mp-wp_genesis 1286 if ( $qv['day'] ) {
mp-wp_genesis 1287 if (! $this->is_date) {
mp-wp_genesis 1288 $this->is_day = true;
mp-wp_genesis 1289 $this->is_date = true;
mp-wp_genesis 1290 }
mp-wp_genesis 1291 }
mp-wp_genesis 1292
mp-wp_genesis 1293 if ( $qv['monthnum'] ) {
mp-wp_genesis 1294 if (! $this->is_date) {
mp-wp_genesis 1295 $this->is_month = true;
mp-wp_genesis 1296 $this->is_date = true;
mp-wp_genesis 1297 }
mp-wp_genesis 1298 }
mp-wp_genesis 1299
mp-wp_genesis 1300 if ( $qv['year'] ) {
mp-wp_genesis 1301 if (! $this->is_date) {
mp-wp_genesis 1302 $this->is_year = true;
mp-wp_genesis 1303 $this->is_date = true;
mp-wp_genesis 1304 }
mp-wp_genesis 1305 }
mp-wp_genesis 1306
mp-wp_genesis 1307 if ( $qv['m'] ) {
mp-wp_genesis 1308 $this->is_date = true;
mp-wp_genesis 1309 if (strlen($qv['m']) > 9) {
mp-wp_genesis 1310 $this->is_time = true;
mp-wp_genesis 1311 } else if (strlen($qv['m']) > 7) {
mp-wp_genesis 1312 $this->is_day = true;
mp-wp_genesis 1313 } else if (strlen($qv['m']) > 5) {
mp-wp_genesis 1314 $this->is_month = true;
mp-wp_genesis 1315 } else {
mp-wp_genesis 1316 $this->is_year = true;
mp-wp_genesis 1317 }
mp-wp_genesis 1318 }
mp-wp_genesis 1319
mp-wp_genesis 1320 if ('' != $qv['w']) {
mp-wp_genesis 1321 $this->is_date = true;
mp-wp_genesis 1322 }
mp-wp_genesis 1323
mp-wp_genesis 1324 if ( empty($qv['cat']) || ($qv['cat'] == '0') ) {
mp-wp_genesis 1325 $this->is_category = false;
mp-wp_genesis 1326 } else {
mp-wp_genesis 1327 if (strpos($qv['cat'], '-') !== false) {
mp-wp_genesis 1328 $this->is_category = false;
mp-wp_genesis 1329 } else {
mp-wp_genesis 1330 $this->is_category = true;
mp-wp_genesis 1331 }
mp-wp_genesis 1332 }
mp-wp_genesis 1333
mp-wp_genesis 1334 if ( '' != $qv['category_name'] ) {
mp-wp_genesis 1335 $this->is_category = true;
mp-wp_genesis 1336 }
mp-wp_genesis 1337
mp-wp_genesis 1338 if ( !is_array($qv['category__in']) || empty($qv['category__in']) ) {
mp-wp_genesis 1339 $qv['category__in'] = array();
mp-wp_genesis 1340 } else {
mp-wp_genesis 1341 $qv['category__in'] = array_map('absint', $qv['category__in']);
mp-wp_genesis 1342 $this->is_category = true;
mp-wp_genesis 1343 }
mp-wp_genesis 1344
mp-wp_genesis 1345 if ( !is_array($qv['category__not_in']) || empty($qv['category__not_in']) ) {
mp-wp_genesis 1346 $qv['category__not_in'] = array();
mp-wp_genesis 1347 } else {
mp-wp_genesis 1348 $qv['category__not_in'] = array_map('absint', $qv['category__not_in']);
mp-wp_genesis 1349 }
mp-wp_genesis 1350
mp-wp_genesis 1351 if ( !is_array($qv['category__and']) || empty($qv['category__and']) ) {
mp-wp_genesis 1352 $qv['category__and'] = array();
mp-wp_genesis 1353 } else {
mp-wp_genesis 1354 $qv['category__and'] = array_map('absint', $qv['category__and']);
mp-wp_genesis 1355 $this->is_category = true;
mp-wp_genesis 1356 }
mp-wp_genesis 1357
mp-wp_genesis 1358 if ( '' != $qv['tag'] )
mp-wp_genesis 1359 $this->is_tag = true;
mp-wp_genesis 1360
mp-wp_genesis 1361 $qv['tag_id'] = absint($qv['tag_id']);
mp-wp_genesis 1362 if ( !empty($qv['tag_id']) )
mp-wp_genesis 1363 $this->is_tag = true;
mp-wp_genesis 1364
mp-wp_genesis 1365 if ( !is_array($qv['tag__in']) || empty($qv['tag__in']) ) {
mp-wp_genesis 1366 $qv['tag__in'] = array();
mp-wp_genesis 1367 } else {
mp-wp_genesis 1368 $qv['tag__in'] = array_map('absint', $qv['tag__in']);
mp-wp_genesis 1369 $this->is_tag = true;
mp-wp_genesis 1370 }
mp-wp_genesis 1371
mp-wp_genesis 1372 if ( !is_array($qv['tag__not_in']) || empty($qv['tag__not_in']) ) {
mp-wp_genesis 1373 $qv['tag__not_in'] = array();
mp-wp_genesis 1374 } else {
mp-wp_genesis 1375 $qv['tag__not_in'] = array_map('absint', $qv['tag__not_in']);
mp-wp_genesis 1376 }
mp-wp_genesis 1377
mp-wp_genesis 1378 if ( !is_array($qv['tag__and']) || empty($qv['tag__and']) ) {
mp-wp_genesis 1379 $qv['tag__and'] = array();
mp-wp_genesis 1380 } else {
mp-wp_genesis 1381 $qv['tag__and'] = array_map('absint', $qv['tag__and']);
mp-wp_genesis 1382 $this->is_category = true;
mp-wp_genesis 1383 }
mp-wp_genesis 1384
mp-wp_genesis 1385 if ( !is_array($qv['tag_slug__in']) || empty($qv['tag_slug__in']) ) {
mp-wp_genesis 1386 $qv['tag_slug__in'] = array();
mp-wp_genesis 1387 } else {
mp-wp_genesis 1388 $qv['tag_slug__in'] = array_map('sanitize_title', $qv['tag_slug__in']);
mp-wp_genesis 1389 $this->is_tag = true;
mp-wp_genesis 1390 }
mp-wp_genesis 1391
mp-wp_genesis 1392 if ( !is_array($qv['tag_slug__and']) || empty($qv['tag_slug__and']) ) {
mp-wp_genesis 1393 $qv['tag_slug__and'] = array();
mp-wp_genesis 1394 } else {
mp-wp_genesis 1395 $qv['tag_slug__and'] = array_map('sanitize_title', $qv['tag_slug__and']);
mp-wp_genesis 1396 $this->is_tag = true;
mp-wp_genesis 1397 }
mp-wp_genesis 1398
mp-wp_genesis 1399 if ( empty($qv['taxonomy']) || empty($qv['term']) ) {
mp-wp_genesis 1400 $this->is_tax = false;
mp-wp_genesis 1401 foreach ( $GLOBALS['wp_taxonomies'] as $t ) {
mp-wp_genesis 1402 if ( isset($t->query_var) && isset($qv[$t->query_var]) && '' != $qv[$t->query_var] ) {
mp-wp_genesis 1403 $this->is_tax = true;
mp-wp_genesis 1404 break;
mp-wp_genesis 1405 }
mp-wp_genesis 1406 }
mp-wp_genesis 1407 } else {
mp-wp_genesis 1408 $this->is_tax = true;
mp-wp_genesis 1409 }
mp-wp_genesis 1410
mp-wp_genesis 1411 if ( empty($qv['author']) || ($qv['author'] == '0') ) {
mp-wp_genesis 1412 $this->is_author = false;
mp-wp_genesis 1413 } else {
mp-wp_genesis 1414 $this->is_author = true;
mp-wp_genesis 1415 }
mp-wp_genesis 1416
mp-wp_genesis 1417 if ( '' != $qv['author_name'] ) {
mp-wp_genesis 1418 $this->is_author = true;
mp-wp_genesis 1419 }
mp-wp_genesis 1420
mp-wp_genesis 1421 if ( ($this->is_date || $this->is_author || $this->is_category || $this->is_tag || $this->is_tax) )
mp-wp_genesis 1422 $this->is_archive = true;
mp-wp_genesis 1423 }
mp-wp_genesis 1424
mp-wp_genesis 1425 if ( '' != $qv['feed'] )
mp-wp_genesis 1426 $this->is_feed = true;
mp-wp_genesis 1427
mp-wp_genesis 1428 if ( '' != $qv['tb'] )
mp-wp_genesis 1429 $this->is_trackback = true;
mp-wp_genesis 1430
mp-wp_genesis 1431 if ( '' != $qv['paged'] )
mp-wp_genesis 1432 $this->is_paged = true;
mp-wp_genesis 1433
mp-wp_genesis 1434 if ( '' != $qv['comments_popup'] )
mp-wp_genesis 1435 $this->is_comments_popup = true;
mp-wp_genesis 1436
mp-wp_genesis 1437 // if we're previewing inside the write screen
mp-wp_genesis 1438 if ('' != $qv['preview'])
mp-wp_genesis 1439 $this->is_preview = true;
mp-wp_genesis 1440
mp-wp_genesis 1441 if ( is_admin() )
mp-wp_genesis 1442 $this->is_admin = true;
mp-wp_genesis 1443
mp-wp_genesis 1444 if ( false !== strpos($qv['feed'], 'comments-') ) {
mp-wp_genesis 1445 $qv['feed'] = str_replace('comments-', '', $qv['feed']);
mp-wp_genesis 1446 $qv['withcomments'] = 1;
mp-wp_genesis 1447 }
mp-wp_genesis 1448
mp-wp_genesis 1449 $this->is_singular = $this->is_single || $this->is_page || $this->is_attachment;
mp-wp_genesis 1450
mp-wp_genesis 1451 if ( $this->is_feed && ( !empty($qv['withcomments']) || ( empty($qv['withoutcomments']) && $this->is_singular ) ) )
mp-wp_genesis 1452 $this->is_comment_feed = true;
mp-wp_genesis 1453
mp-wp_genesis 1454 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 ) )
mp-wp_genesis 1455 $this->is_home = true;
mp-wp_genesis 1456
mp-wp_genesis 1457 // Correct is_* for page_on_front and page_for_posts
mp-wp_genesis 1458 if ( $this->is_home && ( empty($this->query) || $qv['preview'] == 'true' ) && 'page' == get_option('show_on_front') && get_option('page_on_front') ) {
mp-wp_genesis 1459 $this->is_page = true;
mp-wp_genesis 1460 $this->is_home = false;
mp-wp_genesis 1461 $qv['page_id'] = get_option('page_on_front');
mp-wp_genesis 1462 }
mp-wp_genesis 1463
mp-wp_genesis 1464 if ( '' != $qv['pagename'] ) {
mp-wp_genesis 1465 $this->queried_object =& get_page_by_path($qv['pagename']);
mp-wp_genesis 1466 if ( !empty($this->queried_object) )
mp-wp_genesis 1467 $this->queried_object_id = (int) $this->queried_object->ID;
mp-wp_genesis 1468 else
mp-wp_genesis 1469 unset($this->queried_object);
mp-wp_genesis 1470
mp-wp_genesis 1471 if ( 'page' == get_option('show_on_front') && isset($this->queried_object_id) && $this->queried_object_id == get_option('page_for_posts') ) {
mp-wp_genesis 1472 $this->is_page = false;
mp-wp_genesis 1473 $this->is_home = true;
mp-wp_genesis 1474 $this->is_posts_page = true;
mp-wp_genesis 1475 }
mp-wp_genesis 1476 }
mp-wp_genesis 1477
mp-wp_genesis 1478 if ( $qv['page_id'] ) {
mp-wp_genesis 1479 if ( 'page' == get_option('show_on_front') && $qv['page_id'] == get_option('page_for_posts') ) {
mp-wp_genesis 1480 $this->is_page = false;
mp-wp_genesis 1481 $this->is_home = true;
mp-wp_genesis 1482 $this->is_posts_page = true;
mp-wp_genesis 1483 }
mp-wp_genesis 1484 }
mp-wp_genesis 1485
mp-wp_genesis 1486 if ( !empty($qv['post_type']) )
mp-wp_genesis 1487 $qv['post_type'] = sanitize_user($qv['post_type'], true);
mp-wp_genesis 1488
mp-wp_genesis 1489 if ( !empty($qv['post_status']) )
mp-wp_genesis 1490 $qv['post_status'] = preg_replace('|[^a-z0-9_,-]|', '', $qv['post_status']);
mp-wp_genesis 1491
mp-wp_genesis 1492 if ( $this->is_posts_page && ( ! isset($qv['withcomments']) || ! $qv['withcomments'] ) )
mp-wp_genesis 1493 $this->is_comment_feed = false;
mp-wp_genesis 1494
mp-wp_genesis 1495 $this->is_singular = $this->is_single || $this->is_page || $this->is_attachment;
mp-wp_genesis 1496 // Done correcting is_* for page_on_front and page_for_posts
mp-wp_genesis 1497
mp-wp_genesis 1498 if ('404' == $qv['error'])
mp-wp_genesis 1499 $this->set_404();
mp-wp_genesis 1500
mp-wp_genesis 1501 if ( !empty($query) )
mp-wp_genesis 1502 do_action_ref_array('parse_query', array(&$this));
mp-wp_genesis 1503 }
mp-wp_genesis 1504
mp-wp_genesis 1505 /**
mp-wp_genesis 1506 * Sets the 404 property and saves whether query is feed.
mp-wp_genesis 1507 *
mp-wp_genesis 1508 * @since 2.0.0
mp-wp_genesis 1509 * @access public
mp-wp_genesis 1510 */
mp-wp_genesis 1511 function set_404() {
mp-wp_genesis 1512 $is_feed = $this->is_feed;
mp-wp_genesis 1513
mp-wp_genesis 1514 $this->init_query_flags();
mp-wp_genesis 1515 $this->is_404 = true;
mp-wp_genesis 1516
mp-wp_genesis 1517 $this->is_feed = $is_feed;
mp-wp_genesis 1518 }
mp-wp_genesis 1519
mp-wp_genesis 1520 /**
mp-wp_genesis 1521 * Retrieve query variable.
mp-wp_genesis 1522 *
mp-wp_genesis 1523 * @since 1.5.0
mp-wp_genesis 1524 * @access public
mp-wp_genesis 1525 *
mp-wp_genesis 1526 * @param string $query_var Query variable key.
mp-wp_genesis 1527 * @return mixed
mp-wp_genesis 1528 */
mp-wp_genesis 1529 function get($query_var) {
mp-wp_genesis 1530 if (isset($this->query_vars[$query_var])) {
mp-wp_genesis 1531 return $this->query_vars[$query_var];
mp-wp_genesis 1532 }
mp-wp_genesis 1533
mp-wp_genesis 1534 return '';
mp-wp_genesis 1535 }
mp-wp_genesis 1536
mp-wp_genesis 1537 /**
mp-wp_genesis 1538 * Set query variable.
mp-wp_genesis 1539 *
mp-wp_genesis 1540 * @since 1.5.0
mp-wp_genesis 1541 * @access public
mp-wp_genesis 1542 *
mp-wp_genesis 1543 * @param string $query_var Query variable key.
mp-wp_genesis 1544 * @param mixed $value Query variable value.
mp-wp_genesis 1545 */
mp-wp_genesis 1546 function set($query_var, $value) {
mp-wp_genesis 1547 $this->query_vars[$query_var] = $value;
mp-wp_genesis 1548 }
mp-wp_genesis 1549
mp-wp_genesis 1550 /**
mp-wp_genesis 1551 * Retrieve the posts based on query variables.
mp-wp_genesis 1552 *
mp-wp_genesis 1553 * There are a few filters and actions that can be used to modify the post
mp-wp_genesis 1554 * database query.
mp-wp_genesis 1555 *
mp-wp_genesis 1556 * @since 1.5.0
mp-wp_genesis 1557 * @access public
mp-wp_genesis 1558 * @uses do_action_ref_array() Calls 'pre_get_posts' hook before retrieving posts.
mp-wp_genesis 1559 *
mp-wp_genesis 1560 * @return array List of posts.
mp-wp_genesis 1561 */
mp-wp_genesis 1562 function &get_posts() {
mp-wp_genesis 1563 global $wpdb, $user_ID;
mp-wp_genesis 1564
mp-wp_genesis 1565 do_action_ref_array('pre_get_posts', array(&$this));
mp-wp_genesis 1566
mp-wp_genesis 1567 // Shorthand.
mp-wp_genesis 1568 $q = &$this->query_vars;
mp-wp_genesis 1569
mp-wp_genesis 1570 $q = $this->fill_query_vars($q);
mp-wp_genesis 1571
mp-wp_genesis 1572 // First let's clear some variables
mp-wp_genesis 1573 $distinct = '';
mp-wp_genesis 1574 $whichcat = '';
mp-wp_genesis 1575 $whichauthor = '';
mp-wp_genesis 1576 $whichmimetype = '';
mp-wp_genesis 1577 $where = '';
mp-wp_genesis 1578 $limits = '';
mp-wp_genesis 1579 $join = '';
mp-wp_genesis 1580 $search = '';
mp-wp_genesis 1581 $groupby = '';
mp-wp_genesis 1582 $fields = "$wpdb->posts.*";
mp-wp_genesis 1583 $post_status_join = false;
mp-wp_genesis 1584 $page = 1;
mp-wp_genesis 1585
mp-wp_genesis 1586 if ( !isset($q['caller_get_posts']) )
mp-wp_genesis 1587 $q['caller_get_posts'] = false;
mp-wp_genesis 1588
mp-wp_genesis 1589 if ( !isset($q['suppress_filters']) )
mp-wp_genesis 1590 $q['suppress_filters'] = false;
mp-wp_genesis 1591
mp-wp_genesis 1592 if ( !isset($q['post_type']) ) {
mp-wp_genesis 1593 if ( $this->is_search )
mp-wp_genesis 1594 $q['post_type'] = 'any';
mp-wp_genesis 1595 else
mp-wp_genesis 1596 $q['post_type'] = 'post';
mp-wp_genesis 1597 }
mp-wp_genesis 1598 $post_type = $q['post_type'];
mp-wp_genesis 1599 if ( !isset($q['posts_per_page']) || $q['posts_per_page'] == 0 )
mp-wp_genesis 1600 $q['posts_per_page'] = get_option('posts_per_page');
mp-wp_genesis 1601 if ( isset($q['showposts']) && $q['showposts'] ) {
mp-wp_genesis 1602 $q['showposts'] = (int) $q['showposts'];
mp-wp_genesis 1603 $q['posts_per_page'] = $q['showposts'];
mp-wp_genesis 1604 }
mp-wp_genesis 1605 if ( (isset($q['posts_per_archive_page']) && $q['posts_per_archive_page'] != 0) && ($this->is_archive || $this->is_search) )
mp-wp_genesis 1606 $q['posts_per_page'] = $q['posts_per_archive_page'];
mp-wp_genesis 1607 if ( !isset($q['nopaging']) ) {
mp-wp_genesis 1608 if ($q['posts_per_page'] == -1) {
mp-wp_genesis 1609 $q['nopaging'] = true;
mp-wp_genesis 1610 } else {
mp-wp_genesis 1611 $q['nopaging'] = false;
mp-wp_genesis 1612 }
mp-wp_genesis 1613 }
mp-wp_genesis 1614 if ( $this->is_feed ) {
mp-wp_genesis 1615 $q['posts_per_page'] = get_option('posts_per_rss');
mp-wp_genesis 1616 $q['nopaging'] = false;
mp-wp_genesis 1617 }
mp-wp_genesis 1618 $q['posts_per_page'] = (int) $q['posts_per_page'];
mp-wp_genesis 1619 if ( $q['posts_per_page'] < -1 )
mp-wp_genesis 1620 $q['posts_per_page'] = abs($q['posts_per_page']);
mp-wp_genesis 1621 else if ( $q['posts_per_page'] == 0 )
mp-wp_genesis 1622 $q['posts_per_page'] = 1;
mp-wp_genesis 1623
mp-wp_genesis 1624 if ( !isset($q['comments_per_page']) || $q['comments_per_page'] == 0 )
mp-wp_genesis 1625 $q['comments_per_page'] = get_option('comments_per_page');
mp-wp_genesis 1626
mp-wp_genesis 1627 if ( $this->is_home && (empty($this->query) || $q['preview'] == 'true') && ( 'page' == get_option('show_on_front') ) && get_option('page_on_front') ) {
mp-wp_genesis 1628 $this->is_page = true;
mp-wp_genesis 1629 $this->is_home = false;
mp-wp_genesis 1630 $q['page_id'] = get_option('page_on_front');
mp-wp_genesis 1631 }
mp-wp_genesis 1632
mp-wp_genesis 1633 if (isset($q['page'])) {
mp-wp_genesis 1634 $q['page'] = trim($q['page'], '/');
mp-wp_genesis 1635 $q['page'] = absint($q['page']);
mp-wp_genesis 1636 }
mp-wp_genesis 1637
mp-wp_genesis 1638 // If a month is specified in the querystring, load that month
mp-wp_genesis 1639 if ( $q['m'] ) {
mp-wp_genesis 1640 $q['m'] = '' . preg_replace('|[^0-9]|', '', $q['m']);
mp-wp_genesis 1641 $where .= " AND YEAR($wpdb->posts.post_date)=" . substr($q['m'], 0, 4);
mp-wp_genesis 1642 if (strlen($q['m'])>5)
mp-wp_genesis 1643 $where .= " AND MONTH($wpdb->posts.post_date)=" . substr($q['m'], 4, 2);
mp-wp_genesis 1644 if (strlen($q['m'])>7)
mp-wp_genesis 1645 $where .= " AND DAYOFMONTH($wpdb->posts.post_date)=" . substr($q['m'], 6, 2);
mp-wp_genesis 1646 if (strlen($q['m'])>9)
mp-wp_genesis 1647 $where .= " AND HOUR($wpdb->posts.post_date)=" . substr($q['m'], 8, 2);
mp-wp_genesis 1648 if (strlen($q['m'])>11)
mp-wp_genesis 1649 $where .= " AND MINUTE($wpdb->posts.post_date)=" . substr($q['m'], 10, 2);
mp-wp_genesis 1650 if (strlen($q['m'])>13)
mp-wp_genesis 1651 $where .= " AND SECOND($wpdb->posts.post_date)=" . substr($q['m'], 12, 2);
mp-wp_genesis 1652 }
mp-wp_genesis 1653
mp-wp_genesis 1654 if ( '' !== $q['hour'] )
mp-wp_genesis 1655 $where .= " AND HOUR($wpdb->posts.post_date)='" . $q['hour'] . "'";
mp-wp_genesis 1656
mp-wp_genesis 1657 if ( '' !== $q['minute'] )
mp-wp_genesis 1658 $where .= " AND MINUTE($wpdb->posts.post_date)='" . $q['minute'] . "'";
mp-wp_genesis 1659
mp-wp_genesis 1660 if ( '' !== $q['second'] )
mp-wp_genesis 1661 $where .= " AND SECOND($wpdb->posts.post_date)='" . $q['second'] . "'";
mp-wp_genesis 1662
mp-wp_genesis 1663 if ( $q['year'] )
mp-wp_genesis 1664 $where .= " AND YEAR($wpdb->posts.post_date)='" . $q['year'] . "'";
mp-wp_genesis 1665
mp-wp_genesis 1666 if ( $q['monthnum'] )
mp-wp_genesis 1667 $where .= " AND MONTH($wpdb->posts.post_date)='" . $q['monthnum'] . "'";
mp-wp_genesis 1668
mp-wp_genesis 1669 if ( $q['day'] )
mp-wp_genesis 1670 $where .= " AND DAYOFMONTH($wpdb->posts.post_date)='" . $q['day'] . "'";
mp-wp_genesis 1671
mp-wp_genesis 1672 if ('' != $q['name']) {
mp-wp_genesis 1673 $q['name'] = sanitize_title($q['name']);
mp-wp_genesis 1674 $where .= " AND $wpdb->posts.post_name = '" . $q['name'] . "'";
mp-wp_genesis 1675 } else if ('' != $q['pagename']) {
mp-wp_genesis 1676 if ( isset($this->queried_object_id) )
mp-wp_genesis 1677 $reqpage = $this->queried_object_id;
mp-wp_genesis 1678 else {
mp-wp_genesis 1679 $reqpage = get_page_by_path($q['pagename']);
mp-wp_genesis 1680 if ( !empty($reqpage) )
mp-wp_genesis 1681 $reqpage = $reqpage->ID;
mp-wp_genesis 1682 else
mp-wp_genesis 1683 $reqpage = 0;
mp-wp_genesis 1684 }
mp-wp_genesis 1685
mp-wp_genesis 1686 $page_for_posts = get_option('page_for_posts');
mp-wp_genesis 1687 if ( ('page' != get_option('show_on_front') ) || empty($page_for_posts) || ( $reqpage != $page_for_posts ) ) {
mp-wp_genesis 1688 $q['pagename'] = str_replace('%2F', '/', urlencode(urldecode($q['pagename'])));
mp-wp_genesis 1689 $page_paths = '/' . trim($q['pagename'], '/');
mp-wp_genesis 1690 $q['pagename'] = sanitize_title(basename($page_paths));
mp-wp_genesis 1691 $q['name'] = $q['pagename'];
mp-wp_genesis 1692 $where .= " AND ($wpdb->posts.ID = '$reqpage')";
mp-wp_genesis 1693 $reqpage_obj = get_page($reqpage);
mp-wp_genesis 1694 if ( is_object($reqpage_obj) && 'attachment' == $reqpage_obj->post_type ) {
mp-wp_genesis 1695 $this->is_attachment = true;
mp-wp_genesis 1696 $this->is_page = true;
mp-wp_genesis 1697 $q['attachment_id'] = $reqpage;
mp-wp_genesis 1698 }
mp-wp_genesis 1699 }
mp-wp_genesis 1700 } elseif ('' != $q['attachment']) {
mp-wp_genesis 1701 $q['attachment'] = str_replace('%2F', '/', urlencode(urldecode($q['attachment'])));
mp-wp_genesis 1702 $attach_paths = '/' . trim($q['attachment'], '/');
mp-wp_genesis 1703 $q['attachment'] = sanitize_title(basename($attach_paths));
mp-wp_genesis 1704 $q['name'] = $q['attachment'];
mp-wp_genesis 1705 $where .= " AND $wpdb->posts.post_name = '" . $q['attachment'] . "'";
mp-wp_genesis 1706 }
mp-wp_genesis 1707
mp-wp_genesis 1708 if ( $q['w'] )
mp-wp_genesis 1709 $where .= " AND WEEK($wpdb->posts.post_date, 1)='" . $q['w'] . "'";
mp-wp_genesis 1710
mp-wp_genesis 1711 if ( intval($q['comments_popup']) )
mp-wp_genesis 1712 $q['p'] = absint($q['comments_popup']);
mp-wp_genesis 1713
mp-wp_genesis 1714 // If an attachment is requested by number, let it supercede any post number.
mp-wp_genesis 1715 if ( $q['attachment_id'] )
mp-wp_genesis 1716 $q['p'] = absint($q['attachment_id']);
mp-wp_genesis 1717
mp-wp_genesis 1718 // If a post number is specified, load that post
mp-wp_genesis 1719 if ( $q['p'] ) {
mp-wp_genesis 1720 $where .= " AND {$wpdb->posts}.ID = " . $q['p'];
mp-wp_genesis 1721 } elseif ( $q['post__in'] ) {
mp-wp_genesis 1722 $post__in = implode(',', array_map( 'absint', $q['post__in'] ));
mp-wp_genesis 1723 $where .= " AND {$wpdb->posts}.ID IN ($post__in)";
mp-wp_genesis 1724 } elseif ( $q['post__not_in'] ) {
mp-wp_genesis 1725 $post__not_in = implode(',', array_map( 'absint', $q['post__not_in'] ));
mp-wp_genesis 1726 $where .= " AND {$wpdb->posts}.ID NOT IN ($post__not_in)";
mp-wp_genesis 1727 }
mp-wp_genesis 1728
mp-wp_genesis 1729 if ( is_numeric($q['post_parent']) )
mp-wp_genesis 1730 $where .= $wpdb->prepare( " AND $wpdb->posts.post_parent = %d ", $q['post_parent'] );
mp-wp_genesis 1731
mp-wp_genesis 1732 if ( $q['page_id'] ) {
mp-wp_genesis 1733 if ( ('page' != get_option('show_on_front') ) || ( $q['page_id'] != get_option('page_for_posts') ) ) {
mp-wp_genesis 1734 $q['p'] = $q['page_id'];
mp-wp_genesis 1735 $where = " AND {$wpdb->posts}.ID = " . $q['page_id'];
mp-wp_genesis 1736 }
mp-wp_genesis 1737 }
mp-wp_genesis 1738
mp-wp_genesis 1739 // If a search pattern is specified, load the posts that match
mp-wp_genesis 1740 if ( !empty($q['s']) ) {
mp-wp_genesis 1741 // added slashes screw with quote grouping when done early, so done later
mp-wp_genesis 1742 $q['s'] = stripslashes($q['s']);
mp-wp_genesis 1743 if ( !empty($q['sentence']) ) {
mp-wp_genesis 1744 $q['search_terms'] = array($q['s']);
mp-wp_genesis 1745 } else {
mp-wp_genesis 1746 preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $q['s'], $matches);
mp-wp_genesis 1747 $q['search_terms'] = array_map(create_function('$a', 'return trim($a, "\\"\'\\n\\r ");'), $matches[0]);
mp-wp_genesis 1748 }
mp-wp_genesis 1749 $n = !empty($q['exact']) ? '' : '%';
mp-wp_genesis 1750 $searchand = '';
mp-wp_genesis 1751 foreach( (array) $q['search_terms'] as $term) {
mp-wp_genesis 1752 $term = addslashes_gpc($term);
mp-wp_genesis 1753 $search .= "{$searchand}(($wpdb->posts.post_title LIKE '{$n}{$term}{$n}') OR ($wpdb->posts.post_content LIKE '{$n}{$term}{$n}'))";
mp-wp_genesis 1754 $searchand = ' AND ';
mp-wp_genesis 1755 }
mp-wp_genesis 1756 $term = $wpdb->escape($q['s']);
mp-wp_genesis 1757 if (empty($q['sentence']) && count($q['search_terms']) > 1 && $q['search_terms'][0] != $q['s'] )
mp-wp_genesis 1758 $search .= " OR ($wpdb->posts.post_title LIKE '{$n}{$term}{$n}') OR ($wpdb->posts.post_content LIKE '{$n}{$term}{$n}')";
mp-wp_genesis 1759
mp-wp_genesis 1760 if ( !empty($search) )
mp-wp_genesis 1761 $search = " AND ({$search}) ";
mp-wp_genesis 1762 }
mp-wp_genesis 1763
mp-wp_genesis 1764 // Category stuff
mp-wp_genesis 1765
mp-wp_genesis 1766 if ( empty($q['cat']) || ($q['cat'] == '0') ||
mp-wp_genesis 1767 // Bypass cat checks if fetching specific posts
mp-wp_genesis 1768 $this->is_singular ) {
mp-wp_genesis 1769 $whichcat = '';
mp-wp_genesis 1770 } else {
mp-wp_genesis 1771 $q['cat'] = ''.urldecode($q['cat']).'';
mp-wp_genesis 1772 $q['cat'] = addslashes_gpc($q['cat']);
mp-wp_genesis 1773 $cat_array = preg_split('/[,\s]+/', $q['cat']);
mp-wp_genesis 1774 $q['cat'] = '';
mp-wp_genesis 1775 $req_cats = array();
mp-wp_genesis 1776 foreach ( (array) $cat_array as $cat ) {
mp-wp_genesis 1777 $cat = intval($cat);
mp-wp_genesis 1778 $req_cats[] = $cat;
mp-wp_genesis 1779 $in = ($cat > 0);
mp-wp_genesis 1780 $cat = abs($cat);
mp-wp_genesis 1781 if ( $in ) {
mp-wp_genesis 1782 $q['category__in'][] = $cat;
mp-wp_genesis 1783 $q['category__in'] = array_merge($q['category__in'], get_term_children($cat, 'category'));
mp-wp_genesis 1784 } else {
mp-wp_genesis 1785 $q['category__not_in'][] = $cat;
mp-wp_genesis 1786 $q['category__not_in'] = array_merge($q['category__not_in'], get_term_children($cat, 'category'));
mp-wp_genesis 1787 }
mp-wp_genesis 1788 }
mp-wp_genesis 1789 $q['cat'] = implode(',', $req_cats);
mp-wp_genesis 1790 }
mp-wp_genesis 1791
mp-wp_genesis 1792 if ( !empty($q['category__in']) ) {
mp-wp_genesis 1793 $groupby = "{$wpdb->posts}.ID";
mp-wp_genesis 1794 }
mp-wp_genesis 1795
mp-wp_genesis 1796 if ( !empty($q['category__in']) ) {
mp-wp_genesis 1797 $join = " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) ";
mp-wp_genesis 1798 $whichcat .= " AND $wpdb->term_taxonomy.taxonomy = 'category' ";
mp-wp_genesis 1799 $include_cats = "'" . implode("', '", $q['category__in']) . "'";
mp-wp_genesis 1800 $whichcat .= " AND $wpdb->term_taxonomy.term_id IN ($include_cats) ";
mp-wp_genesis 1801 }
mp-wp_genesis 1802
mp-wp_genesis 1803 if ( !empty($q['category__not_in']) ) {
mp-wp_genesis 1804 if ( $wpdb->has_cap( 'subqueries' ) ) {
mp-wp_genesis 1805 $cat_string = "'" . implode("', '", $q['category__not_in']) . "'";
mp-wp_genesis 1806 $whichcat .= " AND $wpdb->posts.ID NOT IN ( SELECT tr.object_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = 'category' AND tt.term_id IN ($cat_string) )";
mp-wp_genesis 1807 } else {
mp-wp_genesis 1808 $ids = get_objects_in_term($q['category__not_in'], 'category');
mp-wp_genesis 1809 if ( is_wp_error( $ids ) )
mp-wp_genesis 1810 $ids = array();
mp-wp_genesis 1811 if ( is_array($ids) && count($ids > 0) ) {
mp-wp_genesis 1812 $out_posts = "'" . implode("', '", $ids) . "'";
mp-wp_genesis 1813 $whichcat .= " AND $wpdb->posts.ID NOT IN ($out_posts)";
mp-wp_genesis 1814 }
mp-wp_genesis 1815 }
mp-wp_genesis 1816 }
mp-wp_genesis 1817
mp-wp_genesis 1818 // Category stuff for nice URLs
mp-wp_genesis 1819 if ( '' != $q['category_name'] && !$this->is_singular ) {
mp-wp_genesis 1820 $reqcat = get_category_by_path($q['category_name']);
mp-wp_genesis 1821 $q['category_name'] = str_replace('%2F', '/', urlencode(urldecode($q['category_name'])));
mp-wp_genesis 1822 $cat_paths = '/' . trim($q['category_name'], '/');
mp-wp_genesis 1823 $q['category_name'] = sanitize_title(basename($cat_paths));
mp-wp_genesis 1824
mp-wp_genesis 1825 $cat_paths = '/' . trim(urldecode($q['category_name']), '/');
mp-wp_genesis 1826 $q['category_name'] = sanitize_title(basename($cat_paths));
mp-wp_genesis 1827 $cat_paths = explode('/', $cat_paths);
mp-wp_genesis 1828 $cat_path = '';
mp-wp_genesis 1829 foreach ( (array) $cat_paths as $pathdir )
mp-wp_genesis 1830 $cat_path .= ( $pathdir != '' ? '/' : '' ) . sanitize_title($pathdir);
mp-wp_genesis 1831
mp-wp_genesis 1832 //if we don't match the entire hierarchy fallback on just matching the nicename
mp-wp_genesis 1833 if ( empty($reqcat) )
mp-wp_genesis 1834 $reqcat = get_category_by_path($q['category_name'], false);
mp-wp_genesis 1835
mp-wp_genesis 1836 if ( !empty($reqcat) )
mp-wp_genesis 1837 $reqcat = $reqcat->term_id;
mp-wp_genesis 1838 else
mp-wp_genesis 1839 $reqcat = 0;
mp-wp_genesis 1840
mp-wp_genesis 1841 $q['cat'] = $reqcat;
mp-wp_genesis 1842
mp-wp_genesis 1843 $join = " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) ";
mp-wp_genesis 1844 $whichcat = " AND $wpdb->term_taxonomy.taxonomy = 'category' ";
mp-wp_genesis 1845 $in_cats = array($q['cat']);
mp-wp_genesis 1846 $in_cats = array_merge($in_cats, get_term_children($q['cat'], 'category'));
mp-wp_genesis 1847 $in_cats = "'" . implode("', '", $in_cats) . "'";
mp-wp_genesis 1848 $whichcat .= "AND $wpdb->term_taxonomy.term_id IN ($in_cats)";
mp-wp_genesis 1849 $groupby = "{$wpdb->posts}.ID";
mp-wp_genesis 1850 }
mp-wp_genesis 1851
mp-wp_genesis 1852 // Tags
mp-wp_genesis 1853 if ( '' != $q['tag'] ) {
mp-wp_genesis 1854 if ( strpos($q['tag'], ',') !== false ) {
mp-wp_genesis 1855 $tags = preg_split('/[,\s]+/', $q['tag']);
mp-wp_genesis 1856 foreach ( (array) $tags as $tag ) {
mp-wp_genesis 1857 $tag = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db');
mp-wp_genesis 1858 $q['tag_slug__in'][] = $tag;
mp-wp_genesis 1859 }
mp-wp_genesis 1860 } else if ( preg_match('/[+\s]+/', $q['tag']) ) {
mp-wp_genesis 1861 $tags = preg_split('/[+\s]+/', $q['tag']);
mp-wp_genesis 1862 foreach ( (array) $tags as $tag ) {
mp-wp_genesis 1863 $tag = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db');
mp-wp_genesis 1864 $q['tag_slug__and'][] = $tag;
mp-wp_genesis 1865 }
mp-wp_genesis 1866 } else {
mp-wp_genesis 1867 $q['tag'] = sanitize_term_field('slug', $q['tag'], 0, 'post_tag', 'db');
mp-wp_genesis 1868 $q['tag_slug__in'][] = $q['tag'];
mp-wp_genesis 1869 }
mp-wp_genesis 1870 }
mp-wp_genesis 1871
mp-wp_genesis 1872 if ( !empty($q['tag__in']) || !empty($q['tag_slug__in']) ) {
mp-wp_genesis 1873 $groupby = "{$wpdb->posts}.ID";
mp-wp_genesis 1874 }
mp-wp_genesis 1875
mp-wp_genesis 1876 if ( !empty($q['tag__in']) ) {
mp-wp_genesis 1877 $join = " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) ";
mp-wp_genesis 1878 $whichcat .= " AND $wpdb->term_taxonomy.taxonomy = 'post_tag' ";
mp-wp_genesis 1879 $include_tags = "'" . implode("', '", $q['tag__in']) . "'";
mp-wp_genesis 1880 $whichcat .= " AND $wpdb->term_taxonomy.term_id IN ($include_tags) ";
mp-wp_genesis 1881 $reqtag = is_term( $q['tag__in'][0], 'post_tag' );
mp-wp_genesis 1882 if ( !empty($reqtag) )
mp-wp_genesis 1883 $q['tag_id'] = $reqtag['term_id'];
mp-wp_genesis 1884 }
mp-wp_genesis 1885
mp-wp_genesis 1886 if ( !empty($q['tag_slug__in']) ) {
mp-wp_genesis 1887 $join = " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) INNER JOIN $wpdb->terms ON ($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id) ";
mp-wp_genesis 1888 $whichcat .= " AND $wpdb->term_taxonomy.taxonomy = 'post_tag' ";
mp-wp_genesis 1889 $include_tags = "'" . implode("', '", $q['tag_slug__in']) . "'";
mp-wp_genesis 1890 $whichcat .= " AND $wpdb->terms.slug IN ($include_tags) ";
mp-wp_genesis 1891 $reqtag = get_term_by( 'slug', $q['tag_slug__in'][0], 'post_tag' );
mp-wp_genesis 1892 if ( !empty($reqtag) )
mp-wp_genesis 1893 $q['tag_id'] = $reqtag->term_id;
mp-wp_genesis 1894 }
mp-wp_genesis 1895
mp-wp_genesis 1896 if ( !empty($q['tag__not_in']) ) {
mp-wp_genesis 1897 if ( $wpdb->has_cap( 'subqueries' ) ) {
mp-wp_genesis 1898 $tag_string = "'" . implode("', '", $q['tag__not_in']) . "'";
mp-wp_genesis 1899 $whichcat .= " AND $wpdb->posts.ID NOT IN ( SELECT tr.object_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = 'post_tag' AND tt.term_id IN ($tag_string) )";
mp-wp_genesis 1900 } else {
mp-wp_genesis 1901 $ids = get_objects_in_term($q['tag__not_in'], 'post_tag');
mp-wp_genesis 1902 if ( is_wp_error( $ids ) )
mp-wp_genesis 1903 $ids = array();
mp-wp_genesis 1904 if ( is_array($ids) && count($ids > 0) ) {
mp-wp_genesis 1905 $out_posts = "'" . implode("', '", $ids) . "'";
mp-wp_genesis 1906 $whichcat .= " AND $wpdb->posts.ID NOT IN ($out_posts)";
mp-wp_genesis 1907 }
mp-wp_genesis 1908 }
mp-wp_genesis 1909 }
mp-wp_genesis 1910
mp-wp_genesis 1911 // Tag and slug intersections.
mp-wp_genesis 1912 $intersections = array('category__and' => 'category', 'tag__and' => 'post_tag', 'tag_slug__and' => 'post_tag');
mp-wp_genesis 1913 foreach ($intersections as $item => $taxonomy) {
mp-wp_genesis 1914 if ( empty($q[$item]) ) continue;
mp-wp_genesis 1915
mp-wp_genesis 1916 if ( $item != 'category__and' ) {
mp-wp_genesis 1917 $reqtag = is_term( $q[$item][0], 'post_tag' );
mp-wp_genesis 1918 if ( !empty($reqtag) )
mp-wp_genesis 1919 $q['tag_id'] = $reqtag['term_id'];
mp-wp_genesis 1920 }
mp-wp_genesis 1921
mp-wp_genesis 1922 $taxonomy_field = $item == 'tag_slug__and' ? 'slug' : 'term_id';
mp-wp_genesis 1923
mp-wp_genesis 1924 $q[$item] = array_unique($q[$item]);
mp-wp_genesis 1925 $tsql = "SELECT p.ID FROM $wpdb->posts p INNER JOIN $wpdb->term_relationships tr ON (p.ID = tr.object_id) INNER JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) INNER JOIN $wpdb->terms t ON (tt.term_id = t.term_id)";
mp-wp_genesis 1926 $tsql .= " WHERE tt.taxonomy = '$taxonomy' AND t.$taxonomy_field IN ('" . implode("', '", $q[$item]) . "')";
mp-wp_genesis 1927 $tsql .= " GROUP BY p.ID HAVING count(p.ID) = " . count($q[$item]);
mp-wp_genesis 1928
mp-wp_genesis 1929 $post_ids = $wpdb->get_col($tsql);
mp-wp_genesis 1930
mp-wp_genesis 1931 if ( count($post_ids) )
mp-wp_genesis 1932 $whichcat .= " AND $wpdb->posts.ID IN (" . implode(', ', $post_ids) . ") ";
mp-wp_genesis 1933 else {
mp-wp_genesis 1934 $whichcat = " AND 0 = 1";
mp-wp_genesis 1935 break;
mp-wp_genesis 1936 }
mp-wp_genesis 1937 }
mp-wp_genesis 1938
mp-wp_genesis 1939 // Taxonomies
mp-wp_genesis 1940 if ( $this->is_tax ) {
mp-wp_genesis 1941 if ( '' != $q['taxonomy'] ) {
mp-wp_genesis 1942 $taxonomy = $q['taxonomy'];
mp-wp_genesis 1943 $tt[$taxonomy] = $q['term'];
mp-wp_genesis 1944 $terms = get_terms($q['taxonomy'], array('slug'=>$q['term']));
mp-wp_genesis 1945 } else {
mp-wp_genesis 1946 foreach ( $GLOBALS['wp_taxonomies'] as $taxonomy => $t ) {
mp-wp_genesis 1947 if ( isset($t->query_var) && '' != $q[$t->query_var] ) {
mp-wp_genesis 1948 $terms = get_terms($taxonomy, array('slug'=>$q[$t->query_var]));
mp-wp_genesis 1949 if ( !is_wp_error($terms) )
mp-wp_genesis 1950 break;
mp-wp_genesis 1951 }
mp-wp_genesis 1952 }
mp-wp_genesis 1953 }
mp-wp_genesis 1954 if ( is_wp_error($terms) || empty($terms) ) {
mp-wp_genesis 1955 $whichcat = " AND 0 ";
mp-wp_genesis 1956 } else {
mp-wp_genesis 1957 foreach ( $terms as $term )
mp-wp_genesis 1958 $term_ids[] = $term->term_id;
mp-wp_genesis 1959 $post_ids = get_objects_in_term($term_ids, $taxonomy);
mp-wp_genesis 1960 if ( !is_wp_error($post_ids) && count($post_ids) ) {
mp-wp_genesis 1961 $whichcat .= " AND $wpdb->posts.ID IN (" . implode(', ', $post_ids) . ") ";
mp-wp_genesis 1962 $post_type = 'any';
mp-wp_genesis 1963 $q['post_status'] = 'publish';
mp-wp_genesis 1964 $post_status_join = true;
mp-wp_genesis 1965 } else {
mp-wp_genesis 1966 $whichcat = " AND 0 ";
mp-wp_genesis 1967 }
mp-wp_genesis 1968 }
mp-wp_genesis 1969 }
mp-wp_genesis 1970
mp-wp_genesis 1971 // Author/user stuff
mp-wp_genesis 1972
mp-wp_genesis 1973 if ( empty($q['author']) || ($q['author'] == '0') ) {
mp-wp_genesis 1974 $whichauthor='';
mp-wp_genesis 1975 } else {
mp-wp_genesis 1976 $q['author'] = ''.urldecode($q['author']).'';
mp-wp_genesis 1977 $q['author'] = addslashes_gpc($q['author']);
mp-wp_genesis 1978 if (strpos($q['author'], '-') !== false) {
mp-wp_genesis 1979 $eq = '!=';
mp-wp_genesis 1980 $andor = 'AND';
mp-wp_genesis 1981 $q['author'] = explode('-', $q['author']);
mp-wp_genesis 1982 $q['author'] = '' . absint($q['author'][1]);
mp-wp_genesis 1983 } else {
mp-wp_genesis 1984 $eq = '=';
mp-wp_genesis 1985 $andor = 'OR';
mp-wp_genesis 1986 }
mp-wp_genesis 1987 $author_array = preg_split('/[,\s]+/', $q['author']);
mp-wp_genesis 1988 $whichauthor .= " AND ($wpdb->posts.post_author ".$eq.' '.absint($author_array[0]);
mp-wp_genesis 1989 for ($i = 1; $i < (count($author_array)); $i = $i + 1) {
mp-wp_genesis 1990 $whichauthor .= ' '.$andor." $wpdb->posts.post_author ".$eq.' '.absint($author_array[$i]);
mp-wp_genesis 1991 }
mp-wp_genesis 1992 $whichauthor .= ')';
mp-wp_genesis 1993 }
mp-wp_genesis 1994
mp-wp_genesis 1995 // Author stuff for nice URLs
mp-wp_genesis 1996
mp-wp_genesis 1997 if ('' != $q['author_name']) {
mp-wp_genesis 1998 if (strpos($q['author_name'], '/') !== false) {
mp-wp_genesis 1999 $q['author_name'] = explode('/',$q['author_name']);
mp-wp_genesis 2000 if ($q['author_name'][count($q['author_name'])-1]) {
mp-wp_genesis 2001 $q['author_name'] = $q['author_name'][count($q['author_name'])-1];#no trailing slash
mp-wp_genesis 2002 } else {
mp-wp_genesis 2003 $q['author_name'] = $q['author_name'][count($q['author_name'])-2];#there was a trailling slash
mp-wp_genesis 2004 }
mp-wp_genesis 2005 }
mp-wp_genesis 2006 $q['author_name'] = sanitize_title($q['author_name']);
mp-wp_genesis 2007 $q['author'] = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_nicename='".$q['author_name']."'");
mp-wp_genesis 2008 $whichauthor .= " AND ($wpdb->posts.post_author = ".absint($q['author']).')';
mp-wp_genesis 2009 }
mp-wp_genesis 2010
mp-wp_genesis 2011 // MIME-Type stuff for attachment browsing
mp-wp_genesis 2012
mp-wp_genesis 2013 if ( isset($q['post_mime_type']) && '' != $q['post_mime_type'] )
mp-wp_genesis 2014 $whichmimetype = wp_post_mime_type_where($q['post_mime_type']);
mp-wp_genesis 2015
mp-wp_genesis 2016 $where .= $search.$whichcat.$whichauthor.$whichmimetype;
mp-wp_genesis 2017
mp-wp_genesis 2018 if ( empty($q['order']) || ((strtoupper($q['order']) != 'ASC') && (strtoupper($q['order']) != 'DESC')) )
mp-wp_genesis 2019 $q['order'] = 'DESC';
mp-wp_genesis 2020
mp-wp_genesis 2021 // Order by
mp-wp_genesis 2022 if ( empty($q['orderby']) ) {
mp-wp_genesis 2023 $q['orderby'] = "$wpdb->posts.post_date ".$q['order'];
mp-wp_genesis 2024 } else {
mp-wp_genesis 2025 // Used to filter values
mp-wp_genesis 2026 $allowed_keys = array('author', 'date', 'category', 'title', 'modified', 'menu_order', 'parent', 'ID', 'rand');
mp-wp_genesis 2027 if ( !empty($q['meta_key']) ) {
mp-wp_genesis 2028 $allowed_keys[] = $q['meta_key'];
mp-wp_genesis 2029 $allowed_keys[] = 'meta_value';
mp-wp_genesis 2030 }
mp-wp_genesis 2031 $q['orderby'] = urldecode($q['orderby']);
mp-wp_genesis 2032 $q['orderby'] = addslashes_gpc($q['orderby']);
mp-wp_genesis 2033 $orderby_array = explode(' ',$q['orderby']);
mp-wp_genesis 2034 if ( empty($orderby_array) )
mp-wp_genesis 2035 $orderby_array[] = $q['orderby'];
mp-wp_genesis 2036 $q['orderby'] = '';
mp-wp_genesis 2037 for ($i = 0; $i < count($orderby_array); $i++) {
mp-wp_genesis 2038 // Only allow certain values for safety
mp-wp_genesis 2039 $orderby = $orderby_array[$i];
mp-wp_genesis 2040 switch ($orderby) {
mp-wp_genesis 2041 case 'menu_order':
mp-wp_genesis 2042 break;
mp-wp_genesis 2043 case 'ID':
mp-wp_genesis 2044 $orderby = "$wpdb->posts.ID";
mp-wp_genesis 2045 break;
mp-wp_genesis 2046 case 'rand':
mp-wp_genesis 2047 $orderby = 'RAND()';
mp-wp_genesis 2048 break;
mp-wp_genesis 2049 case $q['meta_key']:
mp-wp_genesis 2050 case 'meta_value':
mp-wp_genesis 2051 $orderby = "$wpdb->postmeta.meta_value";
mp-wp_genesis 2052 break;
mp-wp_genesis 2053 default:
mp-wp_genesis 2054 $orderby = "$wpdb->posts.post_" . $orderby;
mp-wp_genesis 2055 }
mp-wp_genesis 2056 if ( in_array($orderby_array[$i], $allowed_keys) )
mp-wp_genesis 2057 $q['orderby'] .= (($i == 0) ? '' : ',') . $orderby;
mp-wp_genesis 2058 }
mp-wp_genesis 2059 // append ASC or DESC at the end
mp-wp_genesis 2060 if ( !empty($q['orderby']))
mp-wp_genesis 2061 $q['orderby'] .= " {$q['order']}";
mp-wp_genesis 2062
mp-wp_genesis 2063 if ( empty($q['orderby']) )
mp-wp_genesis 2064 $q['orderby'] = "$wpdb->posts.post_date ".$q['order'];
mp-wp_genesis 2065 }
mp-wp_genesis 2066
mp-wp_genesis 2067 if ( $this->is_attachment ) {
mp-wp_genesis 2068 $where .= " AND $wpdb->posts.post_type = 'attachment'";
mp-wp_genesis 2069 } elseif ($this->is_page) {
mp-wp_genesis 2070 $where .= " AND $wpdb->posts.post_type = 'page'";
mp-wp_genesis 2071 } elseif ($this->is_single) {
mp-wp_genesis 2072 $where .= " AND $wpdb->posts.post_type = 'post'";
mp-wp_genesis 2073 } elseif ( 'any' == $post_type ) {
mp-wp_genesis 2074 $where .= '';
mp-wp_genesis 2075 } else {
mp-wp_genesis 2076 $where .= " AND $wpdb->posts.post_type = '$post_type'";
mp-wp_genesis 2077 }
mp-wp_genesis 2078
mp-wp_genesis 2079 if ( isset($q['post_status']) && '' != $q['post_status'] ) {
mp-wp_genesis 2080 $statuswheres = array();
mp-wp_genesis 2081 $q_status = explode(',', $q['post_status']);
mp-wp_genesis 2082 $r_status = array();
mp-wp_genesis 2083 $p_status = array();
mp-wp_genesis 2084 if ( in_array( 'draft' , $q_status ) )
mp-wp_genesis 2085 $r_status[] = "$wpdb->posts.post_status = 'draft'";
mp-wp_genesis 2086 if ( in_array( 'pending', $q_status ) )
mp-wp_genesis 2087 $r_status[] = "$wpdb->posts.post_status = 'pending'";
mp-wp_genesis 2088 if ( in_array( 'future' , $q_status ) )
mp-wp_genesis 2089 $r_status[] = "$wpdb->posts.post_status = 'future'";
mp-wp_genesis 2090 if ( in_array( 'inherit' , $q_status ) )
mp-wp_genesis 2091 $r_status[] = "$wpdb->posts.post_status = 'inherit'";
mp-wp_genesis 2092 if ( in_array( 'private', $q_status ) )
mp-wp_genesis 2093 $p_status[] = "$wpdb->posts.post_status = 'private'";
mp-wp_genesis 2094 if ( in_array( 'publish', $q_status ) )
mp-wp_genesis 2095 $r_status[] = "$wpdb->posts.post_status = 'publish'";
mp-wp_genesis 2096
mp-wp_genesis 2097 if ( empty($q['perm'] ) || 'readable' != $q['perm'] ) {
mp-wp_genesis 2098 $r_status = array_merge($r_status, $p_status);
mp-wp_genesis 2099 unset($p_status);
mp-wp_genesis 2100 }
mp-wp_genesis 2101
mp-wp_genesis 2102 if ( !empty($r_status) ) {
mp-wp_genesis 2103 if ( !empty($q['perm'] ) && 'editable' == $q['perm'] && !current_user_can("edit_others_{$post_type}s") )
mp-wp_genesis 2104 $statuswheres[] = "($wpdb->posts.post_author = $user_ID " . "AND (" . join( ' OR ', $r_status ) . "))";
mp-wp_genesis 2105 else
mp-wp_genesis 2106 $statuswheres[] = "(" . join( ' OR ', $r_status ) . ")";
mp-wp_genesis 2107 }
mp-wp_genesis 2108 if ( !empty($p_status) ) {
mp-wp_genesis 2109 if ( !empty($q['perm'] ) && 'readable' == $q['perm'] && !current_user_can("read_private_{$post_type}s") )
mp-wp_genesis 2110 $statuswheres[] = "($wpdb->posts.post_author = $user_ID " . "AND (" . join( ' OR ', $p_status ) . "))";
mp-wp_genesis 2111 else
mp-wp_genesis 2112 $statuswheres[] = "(" . join( ' OR ', $p_status ) . ")";
mp-wp_genesis 2113 }
mp-wp_genesis 2114 if ( $post_status_join ) {
mp-wp_genesis 2115 $join .= " LEFT JOIN $wpdb->posts AS p2 ON ($wpdb->posts.post_parent = p2.ID) ";
mp-wp_genesis 2116 foreach ( $statuswheres as $index => $statuswhere )
mp-wp_genesis 2117 $statuswheres[$index] = "($statuswhere OR ($wpdb->posts.post_status = 'inherit' AND " . str_replace($wpdb->posts, 'p2', $statuswhere) . "))";
mp-wp_genesis 2118 }
mp-wp_genesis 2119 foreach ( $statuswheres as $statuswhere )
mp-wp_genesis 2120 $where .= " AND $statuswhere";
mp-wp_genesis 2121 } elseif ( !$this->is_singular ) {
mp-wp_genesis 2122 $where .= " AND ($wpdb->posts.post_status = 'publish'";
mp-wp_genesis 2123
mp-wp_genesis 2124 if ( is_admin() )
mp-wp_genesis 2125 $where .= " OR $wpdb->posts.post_status = 'future' OR $wpdb->posts.post_status = 'draft' OR $wpdb->posts.post_status = 'pending'";
mp-wp_genesis 2126
mp-wp_genesis 2127 if ( is_user_logged_in() ) {
mp-wp_genesis 2128 $where .= current_user_can( "read_private_{$post_type}s" ) ? " OR $wpdb->posts.post_status = 'private'" : " OR $wpdb->posts.post_author = $user_ID AND $wpdb->posts.post_status = 'private'";
mp-wp_genesis 2129 }
mp-wp_genesis 2130
mp-wp_genesis 2131 $where .= ')';
mp-wp_genesis 2132 }
mp-wp_genesis 2133
mp-wp_genesis 2134 // postmeta queries
mp-wp_genesis 2135 if ( ! empty($q['meta_key']) || ! empty($q['meta_value']) )
mp-wp_genesis 2136 $join .= " LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) ";
mp-wp_genesis 2137 if ( ! empty($q['meta_key']) )
mp-wp_genesis 2138 $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_key = %s ", $q['meta_key']);
mp-wp_genesis 2139 if ( ! empty($q['meta_value']) ) {
mp-wp_genesis 2140 if ( ! isset($q['meta_compare']) || empty($q['meta_compare']) || ! in_array($q['meta_compare'], array('=', '!=', '>', '>=', '<', '<=')) )
mp-wp_genesis 2141 $q['meta_compare'] = '=';
mp-wp_genesis 2142
mp-wp_genesis 2143 $where .= $wpdb->prepare("AND $wpdb->postmeta.meta_value {$q['meta_compare']} %s ", $q['meta_value']);
mp-wp_genesis 2144 }
mp-wp_genesis 2145
mp-wp_genesis 2146 // Apply filters on where and join prior to paging so that any
mp-wp_genesis 2147 // manipulations to them are reflected in the paging by day queries.
mp-wp_genesis 2148 if ( !$q['suppress_filters'] ) {
mp-wp_genesis 2149 $where = apply_filters('posts_where', $where);
mp-wp_genesis 2150 $join = apply_filters('posts_join', $join);
mp-wp_genesis 2151 }
mp-wp_genesis 2152
mp-wp_genesis 2153 // Paging
mp-wp_genesis 2154 if ( empty($q['nopaging']) && !$this->is_singular ) {
mp-wp_genesis 2155 $page = absint($q['paged']);
mp-wp_genesis 2156 if (empty($page)) {
mp-wp_genesis 2157 $page = 1;
mp-wp_genesis 2158 }
mp-wp_genesis 2159
mp-wp_genesis 2160 if ( empty($q['offset']) ) {
mp-wp_genesis 2161 $pgstrt = '';
mp-wp_genesis 2162 $pgstrt = ($page - 1) * $q['posts_per_page'] . ', ';
mp-wp_genesis 2163 $limits = 'LIMIT '.$pgstrt.$q['posts_per_page'];
mp-wp_genesis 2164 } else { // we're ignoring $page and using 'offset'
mp-wp_genesis 2165 $q['offset'] = absint($q['offset']);
mp-wp_genesis 2166 $pgstrt = $q['offset'] . ', ';
mp-wp_genesis 2167 $limits = 'LIMIT ' . $pgstrt . $q['posts_per_page'];
mp-wp_genesis 2168 }
mp-wp_genesis 2169 }
mp-wp_genesis 2170
mp-wp_genesis 2171 // Comments feeds
mp-wp_genesis 2172 if ( $this->is_comment_feed && ( $this->is_archive || $this->is_search || !$this->is_singular ) ) {
mp-wp_genesis 2173 if ( $this->is_archive || $this->is_search ) {
mp-wp_genesis 2174 $cjoin = "LEFT JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) $join ";
mp-wp_genesis 2175 $cwhere = "WHERE comment_approved = '1' $where";
mp-wp_genesis 2176 $cgroupby = "GROUP BY $wpdb->comments.comment_id";
mp-wp_genesis 2177 } else { // Other non singular e.g. front
mp-wp_genesis 2178 $cjoin = "LEFT JOIN $wpdb->posts ON ( $wpdb->comments.comment_post_ID = $wpdb->posts.ID )";
mp-wp_genesis 2179 $cwhere = "WHERE post_status = 'publish' AND comment_approved = '1'";
mp-wp_genesis 2180 $cgroupby = '';
mp-wp_genesis 2181 }
mp-wp_genesis 2182
mp-wp_genesis 2183 if ( !$q['suppress_filters'] ) {
mp-wp_genesis 2184 $cjoin = apply_filters('comment_feed_join', $cjoin);
mp-wp_genesis 2185 $cwhere = apply_filters('comment_feed_where', $cwhere);
mp-wp_genesis 2186 $cgroupby = apply_filters('comment_feed_groupby', $cgroupby);
mp-wp_genesis 2187 }
mp-wp_genesis 2188
mp-wp_genesis 2189 $this->comments = (array) $wpdb->get_results("SELECT $distinct $wpdb->comments.* FROM $wpdb->comments $cjoin $cwhere $cgroupby ORDER BY comment_date_gmt DESC LIMIT " . get_option('posts_per_rss'));
mp-wp_genesis 2190 $this->comment_count = count($this->comments);
mp-wp_genesis 2191
mp-wp_genesis 2192 $post_ids = array();
mp-wp_genesis 2193
mp-wp_genesis 2194 foreach ($this->comments as $comment)
mp-wp_genesis 2195 $post_ids[] = (int) $comment->comment_post_ID;
mp-wp_genesis 2196
mp-wp_genesis 2197 $post_ids = join(',', $post_ids);
mp-wp_genesis 2198 $join = '';
mp-wp_genesis 2199 if ( $post_ids )
mp-wp_genesis 2200 $where = "AND $wpdb->posts.ID IN ($post_ids) ";
mp-wp_genesis 2201 else
mp-wp_genesis 2202 $where = "AND 0";
mp-wp_genesis 2203 }
mp-wp_genesis 2204
mp-wp_genesis 2205 $orderby = $q['orderby'];
mp-wp_genesis 2206
mp-wp_genesis 2207 // Apply post-paging filters on where and join. Only plugins that
mp-wp_genesis 2208 // manipulate paging queries should use these hooks.
mp-wp_genesis 2209 if ( !$q['suppress_filters'] ) {
mp-wp_genesis 2210 $where = apply_filters('posts_where_paged', $where);
mp-wp_genesis 2211 $groupby = apply_filters('posts_groupby', $groupby);
mp-wp_genesis 2212 $join = apply_filters('posts_join_paged', $join);
mp-wp_genesis 2213 $orderby = apply_filters('posts_orderby', $orderby);
mp-wp_genesis 2214 $distinct = apply_filters('posts_distinct', $distinct);
mp-wp_genesis 2215 $limits = apply_filters( 'post_limits', $limits );
mp-wp_genesis 2216
mp-wp_genesis 2217 if ( ! empty($q['meta_key']) )
mp-wp_genesis 2218 $fields = "$fields, $wpdb->postmeta.meta_value";
mp-wp_genesis 2219
mp-wp_genesis 2220 $fields = apply_filters('posts_fields', $fields);
mp-wp_genesis 2221 }
mp-wp_genesis 2222
mp-wp_genesis 2223 // Announce current selection parameters. For use by caching plugins.
mp-wp_genesis 2224 do_action( 'posts_selection', $where . $groupby . $orderby . $limits . $join );
mp-wp_genesis 2225
mp-wp_genesis 2226 // Filter again for the benefit of caching plugins. Regular plugins should use the hooks above.
mp-wp_genesis 2227 if ( !$q['suppress_filters'] ) {
mp-wp_genesis 2228 $where = apply_filters('posts_where_request', $where);
mp-wp_genesis 2229 $groupby = apply_filters('posts_groupby_request', $groupby);
mp-wp_genesis 2230 $join = apply_filters('posts_join_request', $join);
mp-wp_genesis 2231 $orderby = apply_filters('posts_orderby_request', $orderby);
mp-wp_genesis 2232 $distinct = apply_filters('posts_distinct_request', $distinct);
mp-wp_genesis 2233 $fields = apply_filters('posts_fields_request', $fields);
mp-wp_genesis 2234 $limits = apply_filters( 'post_limits_request', $limits );
mp-wp_genesis 2235 }
mp-wp_genesis 2236
mp-wp_genesis 2237 if ( ! empty($groupby) )
mp-wp_genesis 2238 $groupby = 'GROUP BY ' . $groupby;
mp-wp_genesis 2239 if ( !empty( $orderby ) )
mp-wp_genesis 2240 $orderby = 'ORDER BY ' . $orderby;
mp-wp_genesis 2241 $found_rows = '';
mp-wp_genesis 2242 if ( !empty($limits) )
mp-wp_genesis 2243 $found_rows = 'SQL_CALC_FOUND_ROWS';
mp-wp_genesis 2244
mp-wp_genesis 2245 $this->request = " SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits";
mp-wp_genesis 2246 if ( !$q['suppress_filters'] )
mp-wp_genesis 2247 $this->request = apply_filters('posts_request', $this->request);
mp-wp_genesis 2248
mp-wp_genesis 2249 $this->posts = $wpdb->get_results($this->request);
mp-wp_genesis 2250 // Raw results filter. Prior to status checks.
mp-wp_genesis 2251 if ( !$q['suppress_filters'] )
mp-wp_genesis 2252 $this->posts = apply_filters('posts_results', $this->posts);
mp-wp_genesis 2253
mp-wp_genesis 2254 if ( !empty($this->posts) && $this->is_comment_feed && $this->is_singular ) {
mp-wp_genesis 2255 $cjoin = apply_filters('comment_feed_join', '');
mp-wp_genesis 2256 $cwhere = apply_filters('comment_feed_where', "WHERE comment_post_ID = '{$this->posts[0]->ID}' AND comment_approved = '1'");
mp-wp_genesis 2257 $comments_request = "SELECT $wpdb->comments.* FROM $wpdb->comments $cjoin $cwhere ORDER BY comment_date_gmt DESC LIMIT " . get_option('posts_per_rss');
mp-wp_genesis 2258 $this->comments = $wpdb->get_results($comments_request);
mp-wp_genesis 2259 $this->comment_count = count($this->comments);
mp-wp_genesis 2260 }
mp-wp_genesis 2261
mp-wp_genesis 2262 if ( !empty($limits) ) {
mp-wp_genesis 2263 $found_posts_query = apply_filters( 'found_posts_query', 'SELECT FOUND_ROWS()' );
mp-wp_genesis 2264 $this->found_posts = $wpdb->get_var( $found_posts_query );
mp-wp_genesis 2265 $this->found_posts = apply_filters( 'found_posts', $this->found_posts );
mp-wp_genesis 2266 $this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']);
mp-wp_genesis 2267 }
mp-wp_genesis 2268
mp-wp_genesis 2269 // Check post status to determine if post should be displayed.
mp-wp_genesis 2270 if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) {
mp-wp_genesis 2271 $status = get_post_status($this->posts[0]);
mp-wp_genesis 2272 //$type = get_post_type($this->posts[0]);
mp-wp_genesis 2273 if ( ('publish' != $status) ) {
mp-wp_genesis 2274 if ( ! is_user_logged_in() ) {
mp-wp_genesis 2275 // User must be logged in to view unpublished posts.
mp-wp_genesis 2276 $this->posts = array();
mp-wp_genesis 2277 } else {
mp-wp_genesis 2278 if (in_array($status, array('draft', 'pending')) ) {
mp-wp_genesis 2279 // User must have edit permissions on the draft to preview.
mp-wp_genesis 2280 if (! current_user_can('edit_post', $this->posts[0]->ID)) {
mp-wp_genesis 2281 $this->posts = array();
mp-wp_genesis 2282 } else {
mp-wp_genesis 2283 $this->is_preview = true;
mp-wp_genesis 2284 $this->posts[0]->post_date = current_time('mysql');
mp-wp_genesis 2285 }
mp-wp_genesis 2286 } else if ('future' == $status) {
mp-wp_genesis 2287 $this->is_preview = true;
mp-wp_genesis 2288 if (!current_user_can('edit_post', $this->posts[0]->ID)) {
mp-wp_genesis 2289 $this->posts = array ( );
mp-wp_genesis 2290 }
mp-wp_genesis 2291 } else {
mp-wp_genesis 2292 if (! current_user_can('read_post', $this->posts[0]->ID))
mp-wp_genesis 2293 $this->posts = array();
mp-wp_genesis 2294 }
mp-wp_genesis 2295 }
mp-wp_genesis 2296 }
mp-wp_genesis 2297
mp-wp_genesis 2298 if ( $this->is_preview && current_user_can( "edit_{$post_type}", $this->posts[0]->ID ) )
mp-wp_genesis 2299 $this->posts[0] = apply_filters('the_preview', $this->posts[0]);
mp-wp_genesis 2300 }
mp-wp_genesis 2301
mp-wp_genesis 2302 // Put sticky posts at the top of the posts array
mp-wp_genesis 2303 $sticky_posts = get_option('sticky_posts');
mp-wp_genesis 2304 if ( $this->is_home && $page <= 1 && !empty($sticky_posts) && !$q['caller_get_posts'] ) {
mp-wp_genesis 2305 $num_posts = count($this->posts);
mp-wp_genesis 2306 $sticky_offset = 0;
mp-wp_genesis 2307 // Loop over posts and relocate stickies to the front.
mp-wp_genesis 2308 for ( $i = 0; $i < $num_posts; $i++ ) {
mp-wp_genesis 2309 if ( in_array($this->posts[$i]->ID, $sticky_posts) ) {
mp-wp_genesis 2310 $sticky_post = $this->posts[$i];
mp-wp_genesis 2311 // Remove sticky from current position
mp-wp_genesis 2312 array_splice($this->posts, $i, 1);
mp-wp_genesis 2313 // Move to front, after other stickies
mp-wp_genesis 2314 array_splice($this->posts, $sticky_offset, 0, array($sticky_post));
mp-wp_genesis 2315 // Increment the sticky offset. The next sticky will be placed at this offset.
mp-wp_genesis 2316 $sticky_offset++;
mp-wp_genesis 2317 // Remove post from sticky posts array
mp-wp_genesis 2318 $offset = array_search($sticky_post->ID, $sticky_posts);
mp-wp_genesis 2319 array_splice($sticky_posts, $offset, 1);
mp-wp_genesis 2320 }
mp-wp_genesis 2321 }
mp-wp_genesis 2322
mp-wp_genesis 2323 // Fetch sticky posts that weren't in the query results
mp-wp_genesis 2324 if ( !empty($sticky_posts) ) {
mp-wp_genesis 2325 $stickies__in = implode(',', array_map( 'absint', $sticky_posts ));
mp-wp_genesis 2326 $stickies = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE $wpdb->posts.ID IN ($stickies__in)" );
mp-wp_genesis 2327 /** @todo Make sure post is published or viewable by the current user */
mp-wp_genesis 2328 foreach ( $stickies as $sticky_post ) {
mp-wp_genesis 2329 if ( 'publish' != $sticky_post->post_status )
mp-wp_genesis 2330 continue;
mp-wp_genesis 2331 array_splice($this->posts, $sticky_offset, 0, array($sticky_post));
mp-wp_genesis 2332 $sticky_offset++;
mp-wp_genesis 2333 }
mp-wp_genesis 2334 }
mp-wp_genesis 2335 }
mp-wp_genesis 2336
mp-wp_genesis 2337 if ( !$q['suppress_filters'] )
mp-wp_genesis 2338 $this->posts = apply_filters('the_posts', $this->posts);
mp-wp_genesis 2339
mp-wp_genesis 2340 update_post_caches($this->posts);
mp-wp_genesis 2341
mp-wp_genesis 2342 $this->post_count = count($this->posts);
mp-wp_genesis 2343 if ($this->post_count > 0) {
mp-wp_genesis 2344 $this->post = $this->posts[0];
mp-wp_genesis 2345 }
mp-wp_genesis 2346
mp-wp_genesis 2347 return $this->posts;
mp-wp_genesis 2348 }
mp-wp_genesis 2349
mp-wp_genesis 2350 /**
mp-wp_genesis 2351 * Setup the next post and iterate current post index.
mp-wp_genesis 2352 *
mp-wp_genesis 2353 * @since 1.5.0
mp-wp_genesis 2354 * @access public
mp-wp_genesis 2355 *
mp-wp_genesis 2356 * @return object Next post.
mp-wp_genesis 2357 */
mp-wp_genesis 2358 function next_post() {
mp-wp_genesis 2359
mp-wp_genesis 2360 $this->current_post++;
mp-wp_genesis 2361
mp-wp_genesis 2362 $this->post = $this->posts[$this->current_post];
mp-wp_genesis 2363 return $this->post;
mp-wp_genesis 2364 }
mp-wp_genesis 2365
mp-wp_genesis 2366 /**
mp-wp_genesis 2367 * Sets up the current post.
mp-wp_genesis 2368 *
mp-wp_genesis 2369 * Retrieves the next post, sets up the post, sets the 'in the loop'
mp-wp_genesis 2370 * property to true.
mp-wp_genesis 2371 *
mp-wp_genesis 2372 * @since 1.5.0
mp-wp_genesis 2373 * @access public
mp-wp_genesis 2374 * @uses $post
mp-wp_genesis 2375 * @uses do_action() Calls 'loop_start' if loop has just started
mp-wp_genesis 2376 */
mp-wp_genesis 2377 function the_post() {
mp-wp_genesis 2378 global $post;
mp-wp_genesis 2379 $this->in_the_loop = true;
mp-wp_genesis 2380 $post = $this->next_post();
mp-wp_genesis 2381 setup_postdata($post);
mp-wp_genesis 2382
mp-wp_genesis 2383 if ( $this->current_post == 0 ) // loop has just started
mp-wp_genesis 2384 do_action('loop_start');
mp-wp_genesis 2385 }
mp-wp_genesis 2386
mp-wp_genesis 2387 /**
mp-wp_genesis 2388 * Whether there are more posts available in the loop.
mp-wp_genesis 2389 *
mp-wp_genesis 2390 * Calls action 'loop_end', when the loop is complete.
mp-wp_genesis 2391 *
mp-wp_genesis 2392 * @since 1.5.0
mp-wp_genesis 2393 * @access public
mp-wp_genesis 2394 * @uses do_action() Calls 'loop_start' if loop has just started
mp-wp_genesis 2395 *
mp-wp_genesis 2396 * @return bool True if posts are available, false if end of loop.
mp-wp_genesis 2397 */
mp-wp_genesis 2398 function have_posts() {
mp-wp_genesis 2399 if ($this->current_post + 1 < $this->post_count) {
mp-wp_genesis 2400 return true;
mp-wp_genesis 2401 } elseif ($this->current_post + 1 == $this->post_count && $this->post_count > 0) {
mp-wp_genesis 2402 do_action('loop_end');
mp-wp_genesis 2403 // Do some cleaning up after the loop
mp-wp_genesis 2404 $this->rewind_posts();
mp-wp_genesis 2405 }
mp-wp_genesis 2406
mp-wp_genesis 2407 $this->in_the_loop = false;
mp-wp_genesis 2408 return false;
mp-wp_genesis 2409 }
mp-wp_genesis 2410
mp-wp_genesis 2411 /**
mp-wp_genesis 2412 * Rewind the posts and reset post index.
mp-wp_genesis 2413 *
mp-wp_genesis 2414 * @since 1.5.0
mp-wp_genesis 2415 * @access public
mp-wp_genesis 2416 */
mp-wp_genesis 2417 function rewind_posts() {
mp-wp_genesis 2418 $this->current_post = -1;
mp-wp_genesis 2419 if ($this->post_count > 0) {
mp-wp_genesis 2420 $this->post = $this->posts[0];
mp-wp_genesis 2421 }
mp-wp_genesis 2422 }
mp-wp_genesis 2423
mp-wp_genesis 2424 /**
mp-wp_genesis 2425 * Iterate current comment index and return comment object.
mp-wp_genesis 2426 *
mp-wp_genesis 2427 * @since 2.2.0
mp-wp_genesis 2428 * @access public
mp-wp_genesis 2429 *
mp-wp_genesis 2430 * @return object Comment object.
mp-wp_genesis 2431 */
mp-wp_genesis 2432 function next_comment() {
mp-wp_genesis 2433 $this->current_comment++;
mp-wp_genesis 2434
mp-wp_genesis 2435 $this->comment = $this->comments[$this->current_comment];
mp-wp_genesis 2436 return $this->comment;
mp-wp_genesis 2437 }
mp-wp_genesis 2438
mp-wp_genesis 2439 /**
mp-wp_genesis 2440 * Sets up the current comment.
mp-wp_genesis 2441 *
mp-wp_genesis 2442 * @since 2.2.0
mp-wp_genesis 2443 * @access public
mp-wp_genesis 2444 * @global object $comment Current comment.
mp-wp_genesis 2445 * @uses do_action() Calls 'comment_loop_start' hook when first comment is processed.
mp-wp_genesis 2446 */
mp-wp_genesis 2447 function the_comment() {
mp-wp_genesis 2448 global $comment;
mp-wp_genesis 2449
mp-wp_genesis 2450 $comment = $this->next_comment();
mp-wp_genesis 2451
mp-wp_genesis 2452 if ($this->current_comment == 0) {
mp-wp_genesis 2453 do_action('comment_loop_start');
mp-wp_genesis 2454 }
mp-wp_genesis 2455 }
mp-wp_genesis 2456
mp-wp_genesis 2457 /**
mp-wp_genesis 2458 * Whether there are more comments available.
mp-wp_genesis 2459 *
mp-wp_genesis 2460 * Automatically rewinds comments when finished.
mp-wp_genesis 2461 *
mp-wp_genesis 2462 * @since 2.2.0
mp-wp_genesis 2463 * @access public
mp-wp_genesis 2464 *
mp-wp_genesis 2465 * @return bool True, if more comments. False, if no more posts.
mp-wp_genesis 2466 */
mp-wp_genesis 2467 function have_comments() {
mp-wp_genesis 2468 if ($this->current_comment + 1 < $this->comment_count) {
mp-wp_genesis 2469 return true;
mp-wp_genesis 2470 } elseif ($this->current_comment + 1 == $this->comment_count) {
mp-wp_genesis 2471 $this->rewind_comments();
mp-wp_genesis 2472 }
mp-wp_genesis 2473
mp-wp_genesis 2474 return false;
mp-wp_genesis 2475 }
mp-wp_genesis 2476
mp-wp_genesis 2477 /**
mp-wp_genesis 2478 * Rewind the comments, resets the comment index and comment to first.
mp-wp_genesis 2479 *
mp-wp_genesis 2480 * @since 2.2.0
mp-wp_genesis 2481 * @access public
mp-wp_genesis 2482 */
mp-wp_genesis 2483 function rewind_comments() {
mp-wp_genesis 2484 $this->current_comment = -1;
mp-wp_genesis 2485 if ($this->comment_count > 0) {
mp-wp_genesis 2486 $this->comment = $this->comments[0];
mp-wp_genesis 2487 }
mp-wp_genesis 2488 }
mp-wp_genesis 2489
mp-wp_genesis 2490 /**
mp-wp_genesis 2491 * Sets up the WordPress query by parsing query string.
mp-wp_genesis 2492 *
mp-wp_genesis 2493 * @since 1.5.0
mp-wp_genesis 2494 * @access public
mp-wp_genesis 2495 *
mp-wp_genesis 2496 * @param string $query URL query string.
mp-wp_genesis 2497 * @return array List of posts.
mp-wp_genesis 2498 */
mp-wp_genesis 2499 function &query($query) {
mp-wp_genesis 2500 $this->parse_query($query);
mp-wp_genesis 2501 return $this->get_posts();
mp-wp_genesis 2502 }
mp-wp_genesis 2503
mp-wp_genesis 2504 /**
mp-wp_genesis 2505 * Retrieve queried object.
mp-wp_genesis 2506 *
mp-wp_genesis 2507 * If queried object is not set, then the queried object will be set from
mp-wp_genesis 2508 * the category, tag, taxonomy, posts page, single post, page, or author
mp-wp_genesis 2509 * query variable. After it is set up, it will be returned.
mp-wp_genesis 2510 *
mp-wp_genesis 2511 * @since 1.5.0
mp-wp_genesis 2512 * @access public
mp-wp_genesis 2513 *
mp-wp_genesis 2514 * @return object
mp-wp_genesis 2515 */
mp-wp_genesis 2516 function get_queried_object() {
mp-wp_genesis 2517 if (isset($this->queried_object)) {
mp-wp_genesis 2518 return $this->queried_object;
mp-wp_genesis 2519 }
mp-wp_genesis 2520
mp-wp_genesis 2521 $this->queried_object = NULL;
mp-wp_genesis 2522 $this->queried_object_id = 0;
mp-wp_genesis 2523
mp-wp_genesis 2524 if ($this->is_category) {
mp-wp_genesis 2525 $cat = $this->get('cat');
mp-wp_genesis 2526 $category = &get_category($cat);
mp-wp_genesis 2527 if ( is_wp_error( $category ) )
mp-wp_genesis 2528 return NULL;
mp-wp_genesis 2529 $this->queried_object = &$category;
mp-wp_genesis 2530 $this->queried_object_id = (int) $cat;
mp-wp_genesis 2531 } else if ($this->is_tag) {
mp-wp_genesis 2532 $tag_id = $this->get('tag_id');
mp-wp_genesis 2533 $tag = &get_term($tag_id, 'post_tag');
mp-wp_genesis 2534 if ( is_wp_error( $tag ) )
mp-wp_genesis 2535 return NULL;
mp-wp_genesis 2536 $this->queried_object = &$tag;
mp-wp_genesis 2537 $this->queried_object_id = (int) $tag_id;
mp-wp_genesis 2538 } else if ($this->is_tax) {
mp-wp_genesis 2539 $tax = $this->get('taxonomy');
mp-wp_genesis 2540 $slug = $this->get('term');
mp-wp_genesis 2541 $term = &get_terms($tax, array('slug'=>$slug));
mp-wp_genesis 2542 if ( is_wp_error($term) || empty($term) )
mp-wp_genesis 2543 return NULL;
mp-wp_genesis 2544 $term = $term[0];
mp-wp_genesis 2545 $this->queried_object = $term;
mp-wp_genesis 2546 $this->queried_object_id = $term->term_id;
mp-wp_genesis 2547 } else if ($this->is_posts_page) {
mp-wp_genesis 2548 $this->queried_object = & get_page(get_option('page_for_posts'));
mp-wp_genesis 2549 $this->queried_object_id = (int) $this->queried_object->ID;
mp-wp_genesis 2550 } else if ($this->is_single) {
mp-wp_genesis 2551 $this->queried_object = $this->post;
mp-wp_genesis 2552 $this->queried_object_id = (int) $this->post->ID;
mp-wp_genesis 2553 } else if ($this->is_page) {
mp-wp_genesis 2554 $this->queried_object = $this->post;
mp-wp_genesis 2555 $this->queried_object_id = (int) $this->post->ID;
mp-wp_genesis 2556 } else if ($this->is_author) {
mp-wp_genesis 2557 $author_id = (int) $this->get('author');
mp-wp_genesis 2558 $author = get_userdata($author_id);
mp-wp_genesis 2559 $this->queried_object = $author;
mp-wp_genesis 2560 $this->queried_object_id = $author_id;
mp-wp_genesis 2561 }
mp-wp_genesis 2562
mp-wp_genesis 2563 return $this->queried_object;
mp-wp_genesis 2564 }
mp-wp_genesis 2565
mp-wp_genesis 2566 /**
mp-wp_genesis 2567 * Retrieve ID of the current queried object.
mp-wp_genesis 2568 *
mp-wp_genesis 2569 * @since 1.5.0
mp-wp_genesis 2570 * @access public
mp-wp_genesis 2571 *
mp-wp_genesis 2572 * @return int
mp-wp_genesis 2573 */
mp-wp_genesis 2574 function get_queried_object_id() {
mp-wp_genesis 2575 $this->get_queried_object();
mp-wp_genesis 2576
mp-wp_genesis 2577 if (isset($this->queried_object_id)) {
mp-wp_genesis 2578 return $this->queried_object_id;
mp-wp_genesis 2579 }
mp-wp_genesis 2580
mp-wp_genesis 2581 return 0;
mp-wp_genesis 2582 }
mp-wp_genesis 2583
mp-wp_genesis 2584 /**
mp-wp_genesis 2585 * PHP4 type constructor.
mp-wp_genesis 2586 *
mp-wp_genesis 2587 * Sets up the WordPress query, if parameter is not empty.
mp-wp_genesis 2588 *
mp-wp_genesis 2589 * @since 1.5.0
mp-wp_genesis 2590 * @access public
mp-wp_genesis 2591 *
mp-wp_genesis 2592 * @param string $query URL query string.
mp-wp_genesis 2593 * @return WP_Query
mp-wp_genesis 2594 */
mp-wp_genesis 2595 function WP_Query ($query = '') {
mp-wp_genesis 2596 if (! empty($query)) {
mp-wp_genesis 2597 $this->query($query);
mp-wp_genesis 2598 }
mp-wp_genesis 2599 }
mp-wp_genesis 2600 }
mp-wp_genesis 2601
mp-wp_genesis 2602 /**
mp-wp_genesis 2603 * Redirect old slugs to the correct permalink.
mp-wp_genesis 2604 *
mp-wp_genesis 2605 * Attempts to find the current slug from the past slugs.
mp-wp_genesis 2606 *
mp-wp_genesis 2607 * @since 2.1.0
mp-wp_genesis 2608 * @uses $wp_query
mp-wp_genesis 2609 * @uses $wpdb
mp-wp_genesis 2610 *
mp-wp_genesis 2611 * @return null If no link is found, null is returned.
mp-wp_genesis 2612 */
mp-wp_genesis 2613 function wp_old_slug_redirect () {
mp-wp_genesis 2614 global $wp_query;
mp-wp_genesis 2615 if ( is_404() && '' != $wp_query->query_vars['name'] ) :
mp-wp_genesis 2616 global $wpdb;
mp-wp_genesis 2617
mp-wp_genesis 2618 $query = "SELECT post_id FROM $wpdb->postmeta, $wpdb->posts WHERE ID = post_id AND meta_key = '_wp_old_slug' AND meta_value='" . $wp_query->query_vars['name'] . "'";
mp-wp_genesis 2619
mp-wp_genesis 2620 // if year, monthnum, or day have been specified, make our query more precise
mp-wp_genesis 2621 // just in case there are multiple identical _wp_old_slug values
mp-wp_genesis 2622 if ( '' != $wp_query->query_vars['year'] )
mp-wp_genesis 2623 $query .= " AND YEAR(post_date) = '{$wp_query->query_vars['year']}'";
mp-wp_genesis 2624 if ( '' != $wp_query->query_vars['monthnum'] )
mp-wp_genesis 2625 $query .= " AND MONTH(post_date) = '{$wp_query->query_vars['monthnum']}'";
mp-wp_genesis 2626 if ( '' != $wp_query->query_vars['day'] )
mp-wp_genesis 2627 $query .= " AND DAYOFMONTH(post_date) = '{$wp_query->query_vars['day']}'";
mp-wp_genesis 2628
mp-wp_genesis 2629 $id = (int) $wpdb->get_var($query);
mp-wp_genesis 2630
mp-wp_genesis 2631 if ( !$id )
mp-wp_genesis 2632 return;
mp-wp_genesis 2633
mp-wp_genesis 2634 $link = get_permalink($id);
mp-wp_genesis 2635
mp-wp_genesis 2636 if ( !$link )
mp-wp_genesis 2637 return;
mp-wp_genesis 2638
mp-wp_genesis 2639 wp_redirect($link, '301'); // Permanent redirect
mp-wp_genesis 2640 exit;
mp-wp_genesis 2641 endif;
mp-wp_genesis 2642 }
mp-wp_genesis 2643
mp-wp_genesis 2644 /**
mp-wp_genesis 2645 * Setup global post data.
mp-wp_genesis 2646 *
mp-wp_genesis 2647 * @since 1.5.0
mp-wp_genesis 2648 *
mp-wp_genesis 2649 * @param object $post Post data.
mp-wp_genesis 2650 * @return bool True when finished.
mp-wp_genesis 2651 */
mp-wp_genesis 2652 function setup_postdata($post) {
mp-wp_genesis 2653 global $id, $authordata, $day, $currentmonth, $page, $pages, $multipage, $more, $numpages;
mp-wp_genesis 2654
mp-wp_genesis 2655 $id = (int) $post->ID;
mp-wp_genesis 2656
mp-wp_genesis 2657 $authordata = get_userdata($post->post_author);
mp-wp_genesis 2658
mp-wp_genesis 2659 $day = mysql2date('d.m.y', $post->post_date);
mp-wp_genesis 2660 $currentmonth = mysql2date('m', $post->post_date);
mp-wp_genesis 2661 $numpages = 1;
mp-wp_genesis 2662 $page = get_query_var('page');
mp-wp_genesis 2663 if ( !$page )
mp-wp_genesis 2664 $page = 1;
mp-wp_genesis 2665 if ( is_single() || is_page() || is_feed() )
mp-wp_genesis 2666 $more = 1;
mp-wp_genesis 2667 $content = $post->post_content;
mp-wp_genesis 2668 if ( strpos( $content, '<!--nextpage-->' ) ) {
mp-wp_genesis 2669 if ( $page > 1 )
mp-wp_genesis 2670 $more = 1;
mp-wp_genesis 2671 $multipage = 1;
mp-wp_genesis 2672 $content = str_replace("\n<!--nextpage-->\n", '<!--nextpage-->', $content);
mp-wp_genesis 2673 $content = str_replace("\n<!--nextpage-->", '<!--nextpage-->', $content);
mp-wp_genesis 2674 $content = str_replace("<!--nextpage-->\n", '<!--nextpage-->', $content);
mp-wp_genesis 2675 $pages = explode('<!--nextpage-->', $content);
mp-wp_genesis 2676 $numpages = count($pages);
mp-wp_genesis 2677 } else {
mp-wp_genesis 2678 $pages[0] = $post->post_content;
mp-wp_genesis 2679 $multipage = 0;
mp-wp_genesis 2680 }
mp-wp_genesis 2681 return true;
mp-wp_genesis 2682 }
mp-wp_genesis 2683
mp-wp_genesis 2684 ?>