wp/wp-includes/query.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    91  * @global WP_Query $wp_query Global WP_Query instance.
    91  * @global WP_Query $wp_query Global WP_Query instance.
    92  *
    92  *
    93  * @param array|string $query Array or string of WP_Query arguments.
    93  * @param array|string $query Array or string of WP_Query arguments.
    94  * @return array List of post objects.
    94  * @return array List of post objects.
    95  */
    95  */
    96 function query_posts($query) {
    96 function query_posts( $query ) {
    97 	$GLOBALS['wp_query'] = new WP_Query();
    97 	$GLOBALS['wp_query'] = new WP_Query();
    98 	return $GLOBALS['wp_query']->query($query);
    98 	return $GLOBALS['wp_query']->query( $query );
    99 }
    99 }
   100 
   100 
   101 /**
   101 /**
   102  * Destroys the previous query and sets up a new query.
   102  * Destroys the previous query and sets up a new query.
   103  *
   103  *
   134 /*
   134 /*
   135  * Query type checks.
   135  * Query type checks.
   136  */
   136  */
   137 
   137 
   138 /**
   138 /**
   139  * Is the query for an existing archive page?
   139  * Determines whether the query is for an existing archive page.
   140  *
   140  *
   141  * Month, Year, Category, Author, Post Type archive...
   141  * Month, Year, Category, Author, Post Type archive...
   142  *
   142  *
       
   143  * For more information on this and similar theme functions, check out
       
   144  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
   145  * Conditional Tags} article in the Theme Developer Handbook.
       
   146  *
   143  * @since 1.5.0
   147  * @since 1.5.0
   144  *
   148  *
   145  * @global WP_Query $wp_query Global WP_Query instance.
   149  * @global WP_Query $wp_query Global WP_Query instance.
   146  *
   150  *
   147  * @return bool
   151  * @return bool
   156 
   160 
   157 	return $wp_query->is_archive();
   161 	return $wp_query->is_archive();
   158 }
   162 }
   159 
   163 
   160 /**
   164 /**
   161  * Is the query for an existing post type archive page?
   165  * Determines whether the query is for an existing post type archive page.
       
   166  *
       
   167  * For more information on this and similar theme functions, check out
       
   168  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
   169  * Conditional Tags} article in the Theme Developer Handbook.
   162  *
   170  *
   163  * @since 3.1.0
   171  * @since 3.1.0
   164  *
   172  *
   165  * @global WP_Query $wp_query Global WP_Query instance.
   173  * @global WP_Query $wp_query Global WP_Query instance.
   166  *
   174  *
   177 
   185 
   178 	return $wp_query->is_post_type_archive( $post_types );
   186 	return $wp_query->is_post_type_archive( $post_types );
   179 }
   187 }
   180 
   188 
   181 /**
   189 /**
   182  * Is the query for an existing attachment page?
   190  * Determines whether the query is for an existing attachment page.
       
   191  *
       
   192  * For more information on this and similar theme functions, check out
       
   193  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
   194  * Conditional Tags} article in the Theme Developer Handbook.
   183  *
   195  *
   184  * @since 2.0.0
   196  * @since 2.0.0
   185  *
   197  *
   186  * @global WP_Query $wp_query Global WP_Query instance.
   198  * @global WP_Query $wp_query Global WP_Query instance.
   187  *
   199  *
   198 
   210 
   199 	return $wp_query->is_attachment( $attachment );
   211 	return $wp_query->is_attachment( $attachment );
   200 }
   212 }
   201 
   213 
   202 /**
   214 /**
   203  * Is the query for an existing author archive page?
   215  * Determines whether the query is for an existing author archive page.
   204  *
   216  *
   205  * If the $author parameter is specified, this function will additionally
   217  * If the $author parameter is specified, this function will additionally
   206  * check if the query is for one of the authors specified.
   218  * check if the query is for one of the authors specified.
   207  *
   219  *
       
   220  * For more information on this and similar theme functions, check out
       
   221  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
   222  * Conditional Tags} article in the Theme Developer Handbook.
       
   223  *
   208  * @since 1.5.0
   224  * @since 1.5.0
   209  *
   225  *
   210  * @global WP_Query $wp_query Global WP_Query instance.
   226  * @global WP_Query $wp_query Global WP_Query instance.
   211  *
   227  *
   212  * @param mixed $author Optional. User ID, nickname, nicename, or array of User IDs, nicknames, and nicenames
   228  * @param mixed $author Optional. User ID, nickname, nicename, or array of User IDs, nicknames, and nicenames
   222 
   238 
   223 	return $wp_query->is_author( $author );
   239 	return $wp_query->is_author( $author );
   224 }
   240 }
   225 
   241 
   226 /**
   242 /**
   227  * Is the query for an existing category archive page?
   243  * Determines whether the query is for an existing category archive page.
   228  *
   244  *
   229  * If the $category parameter is specified, this function will additionally
   245  * If the $category parameter is specified, this function will additionally
   230  * check if the query is for one of the categories specified.
   246  * check if the query is for one of the categories specified.
   231  *
   247  *
       
   248  * For more information on this and similar theme functions, check out
       
   249  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
   250  * Conditional Tags} article in the Theme Developer Handbook.
       
   251  *
   232  * @since 1.5.0
   252  * @since 1.5.0
   233  *
   253  *
   234  * @global WP_Query $wp_query Global WP_Query instance.
   254  * @global WP_Query $wp_query Global WP_Query instance.
   235  *
   255  *
   236  * @param mixed $category Optional. Category ID, name, slug, or array of Category IDs, names, and slugs.
   256  * @param mixed $category Optional. Category ID, name, slug, or array of Category IDs, names, and slugs.
   246 
   266 
   247 	return $wp_query->is_category( $category );
   267 	return $wp_query->is_category( $category );
   248 }
   268 }
   249 
   269 
   250 /**
   270 /**
   251  * Is the query for an existing tag archive page?
   271  * Determines whether the query is for an existing tag archive page.
   252  *
   272  *
   253  * If the $tag parameter is specified, this function will additionally
   273  * If the $tag parameter is specified, this function will additionally
   254  * check if the query is for one of the tags specified.
   274  * check if the query is for one of the tags specified.
   255  *
   275  *
       
   276  * For more information on this and similar theme functions, check out
       
   277  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
   278  * Conditional Tags} article in the Theme Developer Handbook.
       
   279  *
   256  * @since 2.3.0
   280  * @since 2.3.0
   257  *
   281  *
   258  * @global WP_Query $wp_query Global WP_Query instance.
   282  * @global WP_Query $wp_query Global WP_Query instance.
   259  *
   283  *
   260  * @param mixed $tag Optional. Tag ID, name, slug, or array of Tag IDs, names, and slugs.
   284  * @param mixed $tag Optional. Tag ID, name, slug, or array of Tag IDs, names, and slugs.
   270 
   294 
   271 	return $wp_query->is_tag( $tag );
   295 	return $wp_query->is_tag( $tag );
   272 }
   296 }
   273 
   297 
   274 /**
   298 /**
   275  * Is the query for an existing custom taxonomy archive page?
   299  * Determines whether the query is for an existing custom taxonomy archive page.
   276  *
   300  *
   277  * If the $taxonomy parameter is specified, this function will additionally
   301  * If the $taxonomy parameter is specified, this function will additionally
   278  * check if the query is for that specific $taxonomy.
   302  * check if the query is for that specific $taxonomy.
   279  *
   303  *
   280  * If the $term parameter is specified in addition to the $taxonomy parameter,
   304  * If the $term parameter is specified in addition to the $taxonomy parameter,
   281  * this function will additionally check if the query is for one of the terms
   305  * this function will additionally check if the query is for one of the terms
   282  * specified.
   306  * specified.
   283  *
   307  *
       
   308  * For more information on this and similar theme functions, check out
       
   309  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
   310  * Conditional Tags} article in the Theme Developer Handbook.
       
   311  *
   284  * @since 2.5.0
   312  * @since 2.5.0
   285  *
   313  *
   286  * @global WP_Query $wp_query Global WP_Query instance.
   314  * @global WP_Query $wp_query Global WP_Query instance.
   287  *
   315  *
   288  * @param string|array     $taxonomy Optional. Taxonomy slug or slugs.
   316  * @param string|array     $taxonomy Optional. Taxonomy slug or slugs.
   299 
   327 
   300 	return $wp_query->is_tax( $taxonomy, $term );
   328 	return $wp_query->is_tax( $taxonomy, $term );
   301 }
   329 }
   302 
   330 
   303 /**
   331 /**
   304  * Is the query for an existing date archive?
   332  * Determines whether the query is for an existing date archive.
       
   333  *
       
   334  * For more information on this and similar theme functions, check out
       
   335  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
   336  * Conditional Tags} article in the Theme Developer Handbook.
   305  *
   337  *
   306  * @since 1.5.0
   338  * @since 1.5.0
   307  *
   339  *
   308  * @global WP_Query $wp_query Global WP_Query instance.
   340  * @global WP_Query $wp_query Global WP_Query instance.
   309  *
   341  *
   319 
   351 
   320 	return $wp_query->is_date();
   352 	return $wp_query->is_date();
   321 }
   353 }
   322 
   354 
   323 /**
   355 /**
   324  * Is the query for an existing day archive?
   356  * Determines whether the query is for an existing day archive.
       
   357  *
       
   358  * A conditional check to test whether the page is a date-based archive page displaying posts for the current day.
       
   359  *
       
   360  * For more information on this and similar theme functions, check out
       
   361  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
   362  * Conditional Tags} article in the Theme Developer Handbook.
   325  *
   363  *
   326  * @since 1.5.0
   364  * @since 1.5.0
   327  *
   365  *
   328  * @global WP_Query $wp_query Global WP_Query instance.
   366  * @global WP_Query $wp_query Global WP_Query instance.
   329  *
   367  *
   339 
   377 
   340 	return $wp_query->is_day();
   378 	return $wp_query->is_day();
   341 }
   379 }
   342 
   380 
   343 /**
   381 /**
   344  * Is the query for a feed?
   382  * Determines whether the query is for a feed.
       
   383  *
       
   384  * For more information on this and similar theme functions, check out
       
   385  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
   386  * Conditional Tags} article in the Theme Developer Handbook.
   345  *
   387  *
   346  * @since 1.5.0
   388  * @since 1.5.0
   347  *
   389  *
   348  * @global WP_Query $wp_query Global WP_Query instance.
   390  * @global WP_Query $wp_query Global WP_Query instance.
   349  *
   391  *
   380 
   422 
   381 	return $wp_query->is_comment_feed();
   423 	return $wp_query->is_comment_feed();
   382 }
   424 }
   383 
   425 
   384 /**
   426 /**
   385  * Is the query for the front page of the site?
   427  * Determines whether the query is for the front page of the site.
   386  *
   428  *
   387  * This is for what is displayed at your site's main URL.
   429  * This is for what is displayed at your site's main URL.
   388  *
   430  *
   389  * Depends on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_on_front'.
   431  * Depends on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_on_front'.
   390  *
   432  *
   391  * If you set a static page for the front page of your site, this function will return
   433  * If you set a static page for the front page of your site, this function will return
   392  * true when viewing that page.
   434  * true when viewing that page.
   393  *
   435  *
   394  * Otherwise the same as @see is_home()
   436  * Otherwise the same as @see is_home()
   395  *
   437  *
       
   438  * For more information on this and similar theme functions, check out
       
   439  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
   440  * Conditional Tags} article in the Theme Developer Handbook.
       
   441  *
   396  * @since 2.5.0
   442  * @since 2.5.0
   397  *
   443  *
   398  * @global WP_Query $wp_query Global WP_Query instance.
   444  * @global WP_Query $wp_query Global WP_Query instance.
   399  *
   445  *
   400  * @return bool True, if front of site.
   446  * @return bool True, if front of site.
   409 
   455 
   410 	return $wp_query->is_front_page();
   456 	return $wp_query->is_front_page();
   411 }
   457 }
   412 
   458 
   413 /**
   459 /**
   414  * Determines if the query is for the blog homepage.
   460  * Determines whether the query is for the blog homepage.
   415  *
   461  *
   416  * The blog homepage is the page that shows the time-based blog content of the site.
   462  * The blog homepage is the page that shows the time-based blog content of the site.
   417  *
   463  *
   418  * is_home() is dependent on the site's "Front page displays" Reading Settings 'show_on_front'
   464  * is_home() is dependent on the site's "Front page displays" Reading Settings 'show_on_front'
   419  * and 'page_for_posts'.
   465  * and 'page_for_posts'.
   420  *
   466  *
   421  * If a static page is set for the front page of the site, this function will return true only
   467  * If a static page is set for the front page of the site, this function will return true only
   422  * on the page you set as the "Posts page".
   468  * on the page you set as the "Posts page".
   423  *
   469  *
       
   470  * For more information on this and similar theme functions, check out
       
   471  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
   472  * Conditional Tags} article in the Theme Developer Handbook.
       
   473  *
   424  * @since 1.5.0
   474  * @since 1.5.0
   425  *
   475  *
   426  * @see is_front_page()
   476  * @see is_front_page()
   427  * @global WP_Query $wp_query Global WP_Query instance.
   477  * @global WP_Query $wp_query Global WP_Query instance.
   428  *
   478  *
   438 
   488 
   439 	return $wp_query->is_home();
   489 	return $wp_query->is_home();
   440 }
   490 }
   441 
   491 
   442 /**
   492 /**
   443  * Is the query for an existing month archive?
   493  * Determines whether the query is for the Privacy Policy page.
       
   494  *
       
   495  * The Privacy Policy page is the page that shows the Privacy Policy content of the site.
       
   496  *
       
   497  * is_privacy_policy() is dependent on the site's "Change your Privacy Policy page" Privacy Settings 'wp_page_for_privacy_policy'.
       
   498  *
       
   499  * This function will return true only on the page you set as the "Privacy Policy page".
       
   500  *
       
   501  * For more information on this and similar theme functions, check out
       
   502  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
   503  * Conditional Tags} article in the Theme Developer Handbook.
       
   504  *
       
   505  * @since 5.2.0
       
   506  *
       
   507  * @global WP_Query $wp_query Global WP_Query instance.
       
   508  *
       
   509  * @return bool
       
   510  */
       
   511 function is_privacy_policy() {
       
   512 	global $wp_query;
       
   513 
       
   514 	if ( ! isset( $wp_query ) ) {
       
   515 		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
       
   516 		return false;
       
   517 	}
       
   518 
       
   519 	return $wp_query->is_privacy_policy();
       
   520 }
       
   521 
       
   522 /**
       
   523  * Determines whether the query is for an existing month archive.
       
   524  *
       
   525  * For more information on this and similar theme functions, check out
       
   526  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
   527  * Conditional Tags} article in the Theme Developer Handbook.
   444  *
   528  *
   445  * @since 1.5.0
   529  * @since 1.5.0
   446  *
   530  *
   447  * @global WP_Query $wp_query Global WP_Query instance.
   531  * @global WP_Query $wp_query Global WP_Query instance.
   448  *
   532  *
   458 
   542 
   459 	return $wp_query->is_month();
   543 	return $wp_query->is_month();
   460 }
   544 }
   461 
   545 
   462 /**
   546 /**
   463  * Is the query for an existing single page?
   547  * Determines whether the query is for an existing single page.
   464  *
   548  *
   465  * If the $page parameter is specified, this function will additionally
   549  * If the $page parameter is specified, this function will additionally
   466  * check if the query is for one of the pages specified.
   550  * check if the query is for one of the pages specified.
   467  *
   551  *
       
   552  * For more information on this and similar theme functions, check out
       
   553  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
   554  * Conditional Tags} article in the Theme Developer Handbook.
       
   555  *
   468  * @see is_single()
   556  * @see is_single()
   469  * @see is_singular()
   557  * @see is_singular()
   470  *
   558  *
   471  * @since 1.5.0
   559  * @since 1.5.0
   472  *
   560  *
   485 
   573 
   486 	return $wp_query->is_page( $page );
   574 	return $wp_query->is_page( $page );
   487 }
   575 }
   488 
   576 
   489 /**
   577 /**
   490  * Is the query for paged result and not for the first page?
   578  * Determines whether the query is for paged results and not for the first page.
       
   579  *
       
   580  * For more information on this and similar theme functions, check out
       
   581  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
   582  * Conditional Tags} article in the Theme Developer Handbook.
   491  *
   583  *
   492  * @since 1.5.0
   584  * @since 1.5.0
   493  *
   585  *
   494  * @global WP_Query $wp_query Global WP_Query instance.
   586  * @global WP_Query $wp_query Global WP_Query instance.
   495  *
   587  *
   505 
   597 
   506 	return $wp_query->is_paged();
   598 	return $wp_query->is_paged();
   507 }
   599 }
   508 
   600 
   509 /**
   601 /**
   510  * Is the query for a post or page preview?
   602  * Determines whether the query is for a post or page preview.
       
   603  *
       
   604  * For more information on this and similar theme functions, check out
       
   605  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
   606  * Conditional Tags} article in the Theme Developer Handbook.
   511  *
   607  *
   512  * @since 2.0.0
   608  * @since 2.0.0
   513  *
   609  *
   514  * @global WP_Query $wp_query Global WP_Query instance.
   610  * @global WP_Query $wp_query Global WP_Query instance.
   515  *
   611  *
   545 
   641 
   546 	return $wp_query->is_robots();
   642 	return $wp_query->is_robots();
   547 }
   643 }
   548 
   644 
   549 /**
   645 /**
   550  * Is the query for a search?
   646  * Determines whether the query is for a search.
       
   647  *
       
   648  * For more information on this and similar theme functions, check out
       
   649  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
   650  * Conditional Tags} article in the Theme Developer Handbook.
   551  *
   651  *
   552  * @since 1.5.0
   652  * @since 1.5.0
   553  *
   653  *
   554  * @global WP_Query $wp_query Global WP_Query instance.
   654  * @global WP_Query $wp_query Global WP_Query instance.
   555  *
   655  *
   565 
   665 
   566 	return $wp_query->is_search();
   666 	return $wp_query->is_search();
   567 }
   667 }
   568 
   668 
   569 /**
   669 /**
   570  * Is the query for an existing single post?
   670  * Determines whether the query is for an existing single post.
   571  *
   671  *
   572  * Works for any post type, except attachments and pages
   672  * Works for any post type, except attachments and pages
   573  *
   673  *
   574  * If the $post parameter is specified, this function will additionally
   674  * If the $post parameter is specified, this function will additionally
   575  * check if the query is for one of the Posts specified.
   675  * check if the query is for one of the Posts specified.
   576  *
   676  *
       
   677  * For more information on this and similar theme functions, check out
       
   678  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
   679  * Conditional Tags} article in the Theme Developer Handbook.
       
   680  *
   577  * @see is_page()
   681  * @see is_page()
   578  * @see is_singular()
   682  * @see is_singular()
   579  *
   683  *
   580  * @since 1.5.0
   684  * @since 1.5.0
   581  *
   685  *
   594 
   698 
   595 	return $wp_query->is_single( $post );
   699 	return $wp_query->is_single( $post );
   596 }
   700 }
   597 
   701 
   598 /**
   702 /**
   599  * Is the query for an existing single post of any post type (post, attachment, page,
   703  * Determines whether the query is for an existing single post of any post type
   600  * custom post types)?
   704  * (post, attachment, page, custom post types).
   601  *
   705  *
   602  * If the $post_types parameter is specified, this function will additionally
   706  * If the $post_types parameter is specified, this function will additionally
   603  * check if the query is for one of the Posts Types specified.
   707  * check if the query is for one of the Posts Types specified.
   604  *
   708  *
       
   709  * For more information on this and similar theme functions, check out
       
   710  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
   711  * Conditional Tags} article in the Theme Developer Handbook.
       
   712  *
   605  * @see is_page()
   713  * @see is_page()
   606  * @see is_single()
   714  * @see is_single()
   607  *
   715  *
   608  * @since 1.5.0
   716  * @since 1.5.0
   609  *
   717  *
   622 
   730 
   623 	return $wp_query->is_singular( $post_types );
   731 	return $wp_query->is_singular( $post_types );
   624 }
   732 }
   625 
   733 
   626 /**
   734 /**
   627  * Is the query for a specific time?
   735  * Determines whether the query is for a specific time.
       
   736  *
       
   737  * For more information on this and similar theme functions, check out
       
   738  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
   739  * Conditional Tags} article in the Theme Developer Handbook.
   628  *
   740  *
   629  * @since 1.5.0
   741  * @since 1.5.0
   630  *
   742  *
   631  * @global WP_Query $wp_query Global WP_Query instance.
   743  * @global WP_Query $wp_query Global WP_Query instance.
   632  *
   744  *
   642 
   754 
   643 	return $wp_query->is_time();
   755 	return $wp_query->is_time();
   644 }
   756 }
   645 
   757 
   646 /**
   758 /**
   647  * Is the query for a trackback endpoint call?
   759  * Determines whether the query is for a trackback endpoint call.
       
   760  *
       
   761  * For more information on this and similar theme functions, check out
       
   762  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
   763  * Conditional Tags} article in the Theme Developer Handbook.
   648  *
   764  *
   649  * @since 1.5.0
   765  * @since 1.5.0
   650  *
   766  *
   651  * @global WP_Query $wp_query Global WP_Query instance.
   767  * @global WP_Query $wp_query Global WP_Query instance.
   652  *
   768  *
   662 
   778 
   663 	return $wp_query->is_trackback();
   779 	return $wp_query->is_trackback();
   664 }
   780 }
   665 
   781 
   666 /**
   782 /**
   667  * Is the query for an existing year archive?
   783  * Determines whether the query is for an existing year archive.
       
   784  *
       
   785  * For more information on this and similar theme functions, check out
       
   786  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
   787  * Conditional Tags} article in the Theme Developer Handbook.
   668  *
   788  *
   669  * @since 1.5.0
   789  * @since 1.5.0
   670  *
   790  *
   671  * @global WP_Query $wp_query Global WP_Query instance.
   791  * @global WP_Query $wp_query Global WP_Query instance.
   672  *
   792  *
   682 
   802 
   683 	return $wp_query->is_year();
   803 	return $wp_query->is_year();
   684 }
   804 }
   685 
   805 
   686 /**
   806 /**
   687  * Is the query a 404 (returns no results)?
   807  * Determines whether the query has resulted in a 404 (returns no results).
       
   808  *
       
   809  * For more information on this and similar theme functions, check out
       
   810  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
   811  * Conditional Tags} article in the Theme Developer Handbook.
   688  *
   812  *
   689  * @since 1.5.0
   813  * @since 1.5.0
   690  *
   814  *
   691  * @global WP_Query $wp_query Global WP_Query instance.
   815  * @global WP_Query $wp_query Global WP_Query instance.
   692  *
   816  *
   722 
   846 
   723 	return $wp_query->is_embed();
   847 	return $wp_query->is_embed();
   724 }
   848 }
   725 
   849 
   726 /**
   850 /**
   727  * Is the query the main query?
   851  * Determines whether the query is the main query.
       
   852  *
       
   853  * For more information on this and similar theme functions, check out
       
   854  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
   855  * Conditional Tags} article in the Theme Developer Handbook.
   728  *
   856  *
   729  * @since 3.3.0
   857  * @since 3.3.0
   730  *
   858  *
   731  * @global WP_Query $wp_query Global WP_Query instance.
   859  * @global WP_Query $wp_query Global WP_Query instance.
   732  *
   860  *
   766 	global $wp_query;
   894 	global $wp_query;
   767 	return $wp_query->have_posts();
   895 	return $wp_query->have_posts();
   768 }
   896 }
   769 
   897 
   770 /**
   898 /**
   771  * Whether the caller is in the Loop.
   899  * Determines whether the caller is in the Loop.
       
   900  *
       
   901  * For more information on this and similar theme functions, check out
       
   902  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
   903  * Conditional Tags} article in the Theme Developer Handbook.
   772  *
   904  *
   773  * @since 2.0.0
   905  * @since 2.0.0
   774  *
   906  *
   775  * @global WP_Query $wp_query Global WP_Query instance.
   907  * @global WP_Query $wp_query Global WP_Query instance.
   776  *
   908  *
   890 
  1022 
   891 		$link = get_permalink( $id );
  1023 		$link = get_permalink( $id );
   892 
  1024 
   893 		if ( get_query_var( 'paged' ) > 1 ) {
  1025 		if ( get_query_var( 'paged' ) > 1 ) {
   894 			$link = user_trailingslashit( trailingslashit( $link ) . 'page/' . get_query_var( 'paged' ) );
  1026 			$link = user_trailingslashit( trailingslashit( $link ) . 'page/' . get_query_var( 'paged' ) );
   895 		} elseif( is_embed() ) {
  1027 		} elseif ( is_embed() ) {
   896 			$link = user_trailingslashit( trailingslashit( $link ) . 'embed' );
  1028 			$link = user_trailingslashit( trailingslashit( $link ) . 'embed' );
   897 		}
  1029 		}
   898 
  1030 
   899 		/**
  1031 		/**
   900 		 * Filters the old slug redirect URL.
  1032 		 * Filters the old slug redirect URL.
   933 	$query = $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta, $wpdb->posts WHERE ID = post_id AND post_type = %s AND meta_key = '_wp_old_slug' AND meta_value = %s", $post_type, get_query_var( 'name' ) );
  1065 	$query = $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta, $wpdb->posts WHERE ID = post_id AND post_type = %s AND meta_key = '_wp_old_slug' AND meta_value = %s", $post_type, get_query_var( 'name' ) );
   934 
  1066 
   935 	// if year, monthnum, or day have been specified, make our query more precise
  1067 	// if year, monthnum, or day have been specified, make our query more precise
   936 	// just in case there are multiple identical _wp_old_slug values
  1068 	// just in case there are multiple identical _wp_old_slug values
   937 	if ( get_query_var( 'year' ) ) {
  1069 	if ( get_query_var( 'year' ) ) {
   938 		$query .= $wpdb->prepare( " AND YEAR(post_date) = %d", get_query_var( 'year' ) );
  1070 		$query .= $wpdb->prepare( ' AND YEAR(post_date) = %d', get_query_var( 'year' ) );
   939 	}
  1071 	}
   940 	if ( get_query_var( 'monthnum' ) ) {
  1072 	if ( get_query_var( 'monthnum' ) ) {
   941 		$query .= $wpdb->prepare( " AND MONTH(post_date) = %d", get_query_var( 'monthnum' ) );
  1073 		$query .= $wpdb->prepare( ' AND MONTH(post_date) = %d', get_query_var( 'monthnum' ) );
   942 	}
  1074 	}
   943 	if ( get_query_var( 'day' ) ) {
  1075 	if ( get_query_var( 'day' ) ) {
   944 		$query .= $wpdb->prepare( " AND DAYOFMONTH(post_date) = %d", get_query_var( 'day' ) );
  1076 		$query .= $wpdb->prepare( ' AND DAYOFMONTH(post_date) = %d', get_query_var( 'day' ) );
   945 	}
  1077 	}
   946 
  1078 
   947 	$id = (int) $wpdb->get_var( $query );
  1079 	$id = (int) $wpdb->get_var( $query );
   948 
  1080 
   949 	return $id;
  1081 	return $id;
   965 function _find_post_by_old_date( $post_type ) {
  1097 function _find_post_by_old_date( $post_type ) {
   966 	global $wpdb;
  1098 	global $wpdb;
   967 
  1099 
   968 	$date_query = '';
  1100 	$date_query = '';
   969 	if ( get_query_var( 'year' ) ) {
  1101 	if ( get_query_var( 'year' ) ) {
   970 		$date_query .= $wpdb->prepare( " AND YEAR(pm_date.meta_value) = %d", get_query_var( 'year' ) );
  1102 		$date_query .= $wpdb->prepare( ' AND YEAR(pm_date.meta_value) = %d', get_query_var( 'year' ) );
   971 	}
  1103 	}
   972 	if ( get_query_var( 'monthnum' ) ) {
  1104 	if ( get_query_var( 'monthnum' ) ) {
   973 		$date_query .= $wpdb->prepare( " AND MONTH(pm_date.meta_value) = %d", get_query_var( 'monthnum' ) );
  1105 		$date_query .= $wpdb->prepare( ' AND MONTH(pm_date.meta_value) = %d', get_query_var( 'monthnum' ) );
   974 	}
  1106 	}
   975 	if ( get_query_var( 'day' ) ) {
  1107 	if ( get_query_var( 'day' ) ) {
   976 		$date_query .= $wpdb->prepare( " AND DAYOFMONTH(pm_date.meta_value) = %d", get_query_var( 'day' ) );
  1108 		$date_query .= $wpdb->prepare( ' AND DAYOFMONTH(pm_date.meta_value) = %d', get_query_var( 'day' ) );
   977 	}
  1109 	}
   978 
  1110 
   979 	$id = 0;
  1111 	$id = 0;
   980 	if ( $date_query ) {
  1112 	if ( $date_query ) {
   981 		$id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta AS pm_date, $wpdb->posts WHERE ID = post_id AND post_type = %s AND meta_key = '_wp_old_date' AND post_name = %s" . $date_query, $post_type, get_query_var( 'name' ) ) );
  1113 		$id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta AS pm_date, $wpdb->posts WHERE ID = post_id AND post_type = %s AND meta_key = '_wp_old_date' AND post_name = %s" . $date_query, $post_type, get_query_var( 'name' ) ) );
  1007 		return $wp_query->setup_postdata( $post );
  1139 		return $wp_query->setup_postdata( $post );
  1008 	}
  1140 	}
  1009 
  1141 
  1010 	return false;
  1142 	return false;
  1011 }
  1143 }
       
  1144 
       
  1145 /**
       
  1146  * Generates post data.
       
  1147  *
       
  1148  * @since 5.2.0
       
  1149  *
       
  1150  * @global WP_Query $wp_query Global WP_Query instance.
       
  1151  *
       
  1152  * @param WP_Post|object|int $post WP_Post instance or Post ID/object.
       
  1153  * @return array|bool Elements of post, or false on failure.
       
  1154  */
       
  1155 function generate_postdata( $post ) {
       
  1156 	global $wp_query;
       
  1157 
       
  1158 	if ( ! empty( $wp_query ) && $wp_query instanceof WP_Query ) {
       
  1159 		return $wp_query->generate_postdata( $post );
       
  1160 	}
       
  1161 
       
  1162 	return false;
       
  1163 }