| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Source view] [Print] [Project Stats]
WordPress Query API The query API attempts to get which part of WordPress the user is on. It also provides functionality for getting URL query information.
| File Size: | 1609 lines (49 kb) |
| Included or required: | 0 times |
| Referenced: | 0 times |
| Includes or requires: | 0 files |
| get_query_var( $query_var, $default_value = '' ) X-Ref |
| Retrieves the value of a query variable in the WP_Query class. param: string $query_var The variable key to retrieve. param: mixed $default_value Optional. Value to return if the query variable is not set. return: mixed Contents of the query variable. |
| get_queried_object() X-Ref |
| Retrieves the currently queried object. Wrapper for WP_Query::get_queried_object(). return: WP_Term|WP_Post_Type|WP_Post|WP_User|null The queried object. |
| get_queried_object_id() X-Ref |
| Retrieves the ID of the currently queried object. Wrapper for WP_Query::get_queried_object_id(). return: int ID of the queried object. |
| set_query_var( $query_var, $value ) X-Ref |
| Sets the value of a query variable in the WP_Query class. param: string $query_var Query variable key. param: mixed $value Query variable value. |
| query_posts( $query ) X-Ref |
| Sets up The Loop with query parameters. Note: This function will completely override the main query and isn't intended for use by plugins or themes. Its overly-simplistic approach to modifying the main query can be problematic and should be avoided wherever possible. In most cases, there are better, more performant options for modifying the main query such as via the {@see 'pre_get_posts'} action within WP_Query. This must not be used within the WordPress Loop. param: array|string $query Array or string of WP_Query arguments. return: WP_Post[]|int[] Array of post objects or post IDs. |
| wp_reset_query() X-Ref |
| Destroys the previous query and sets up a new query. This should be used after query_posts() and before another query_posts(). This will remove obscure bugs that occur when the previous WP_Query object is not destroyed properly before another is set up. |
| wp_reset_postdata() X-Ref |
| After looping through a separate query, this function restores the $post global to the current post in the main query. |
| is_archive() X-Ref |
| Determines whether the query is for an existing archive page. Archive pages include category, tag, author, date, custom post type, and custom taxonomy based archives. For more information on this and similar theme functions, check out the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags} article in the Theme Developer Handbook. return: bool Whether the query is for an existing archive page. |
| is_post_type_archive( $post_types = '' ) X-Ref |
| Determines whether the query is for an existing post type archive page. For more information on this and similar theme functions, check out the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags} article in the Theme Developer Handbook. param: string|string[] $post_types Optional. Post type or array of posts types return: bool Whether the query is for an existing post type archive page. |
| is_attachment( $attachment = '' ) X-Ref |
| Determines whether the query is for an existing attachment page. For more information on this and similar theme functions, check out the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags} article in the Theme Developer Handbook. param: int|string|int[]|string[] $attachment Optional. Attachment ID, title, slug, or array of such return: bool Whether the query is for an existing attachment page. |
| is_author( $author = '' ) X-Ref |
| Determines whether the query is for an existing author archive page. If the $author parameter is specified, this function will additionally check if the query is for one of the authors specified. For more information on this and similar theme functions, check out the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags} article in the Theme Developer Handbook. param: int|string|int[]|string[] $author Optional. User ID, nickname, nicename, or array of such return: bool Whether the query is for an existing author archive page. |
| is_category( $category = '' ) X-Ref |
| Determines whether the query is for an existing category archive page. If the $category parameter is specified, this function will additionally check if the query is for one of the categories specified. For more information on this and similar theme functions, check out the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags} article in the Theme Developer Handbook. param: int|string|int[]|string[] $category Optional. Category ID, name, slug, or array of such return: bool Whether the query is for an existing category archive page. |
| is_tag( $tag = '' ) X-Ref |
| Determines whether the query is for an existing tag archive page. If the $tag parameter is specified, this function will additionally check if the query is for one of the tags specified. For more information on this and similar theme functions, check out the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags} article in the Theme Developer Handbook. param: int|string|int[]|string[] $tag Optional. Tag ID, name, slug, or array of such return: bool Whether the query is for an existing tag archive page. |
| is_tax( $taxonomy = '', $term = '' ) X-Ref |
| Determines whether the query is for an existing custom taxonomy archive page. If the $taxonomy parameter is specified, this function will additionally check if the query is for that specific $taxonomy. If the $term parameter is specified in addition to the $taxonomy parameter, this function will additionally check if the query is for one of the terms specified. For more information on this and similar theme functions, check out the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags} article in the Theme Developer Handbook. param: string|string[] $taxonomy Optional. Taxonomy slug or slugs to check against. param: int|string|int[]|string[] $term Optional. Term ID, name, slug, or array of such return: bool Whether the query is for an existing custom taxonomy archive page. |
| is_date() X-Ref |
| Determines whether the query is for an existing date archive. For more information on this and similar theme functions, check out the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags} article in the Theme Developer Handbook. return: bool Whether the query is for an existing date archive. |
| is_day() X-Ref |
| Determines whether the query is for an existing day archive. A conditional check to test whether the page is a date-based archive page displaying posts for the current day. For more information on this and similar theme functions, check out the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags} article in the Theme Developer Handbook. return: bool Whether the query is for an existing day archive. |
| is_feed( $feeds = '' ) X-Ref |
| Determines whether the query is for a feed. For more information on this and similar theme functions, check out the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags} article in the Theme Developer Handbook. param: string|string[] $feeds Optional. Feed type or array of feed types return: bool Whether the query is for a feed. |
| is_comment_feed() X-Ref |
| Is the query for a comments feed? return: bool Whether the query is for a comments feed. |
| is_front_page() X-Ref |
| Determines whether the query is for the front page of the site. This is for what is displayed at your site's main URL. Depends on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_on_front'. If you set a static page for the front page of your site, this function will return true when viewing that page. Otherwise the same as {@see is_home()}. For more information on this and similar theme functions, check out the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags} article in the Theme Developer Handbook. return: bool Whether the query is for the front page of the site. |
| is_home() X-Ref |
| Determines whether the query is for the blog homepage. The blog homepage is the page that shows the time-based blog content of the site. is_home() is dependent on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_for_posts'. If a static page is set for the front page of the site, this function will return true only on the page you set as the "Posts page". For more information on this and similar theme functions, check out the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags} article in the Theme Developer Handbook. return: bool Whether the query is for the blog homepage. |
| is_privacy_policy() X-Ref |
| Determines whether the query is for the Privacy Policy page. The Privacy Policy page is the page that shows the Privacy Policy content of the site. is_privacy_policy() is dependent on the site's "Change your Privacy Policy page" Privacy Settings 'wp_page_for_privacy_policy'. This function will return true only on the page you set as the "Privacy Policy page". For more information on this and similar theme functions, check out the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags} article in the Theme Developer Handbook. return: bool Whether the query is for the Privacy Policy page. |
| is_month() X-Ref |
| Determines whether the query is for an existing month archive. For more information on this and similar theme functions, check out the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags} article in the Theme Developer Handbook. return: bool Whether the query is for an existing month archive. |
| is_page( $page = '' ) X-Ref |
| Determines whether the query is for an existing single page. If the $page parameter is specified, this function will additionally check if the query is for one of the pages specified. For more information on this and similar theme functions, check out the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags} article in the Theme Developer Handbook. param: int|string|int[]|string[] $page Optional. Page ID, title, slug, or array of such return: bool Whether the query is for an existing single page. |
| is_paged() X-Ref |
| Determines whether the query is for a paged result and not for the first page. For more information on this and similar theme functions, check out the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags} article in the Theme Developer Handbook. return: bool Whether the query is for a paged result. |
| is_preview() X-Ref |
| Determines whether the query is for a post or page preview. For more information on this and similar theme functions, check out the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags} article in the Theme Developer Handbook. return: bool Whether the query is for a post or page preview. |
| is_robots() X-Ref |
| Is the query for the robots.txt file? return: bool Whether the query is for the robots.txt file. |
| is_favicon() X-Ref |
| Is the query for the favicon.ico file? return: bool Whether the query is for the favicon.ico file. |
| is_sitemap() X-Ref |
| Is the query for a sitemap? return: bool Whether the query is for a sitemap. |
| is_random() X-Ref |
| Determines whether the query is for random content. True for a blog home, archive or search request that includes the `random` query variable, for example `example.com/random/` or `example.com/random/category/news/`. return: bool Whether the query is for random content. |
| is_search() X-Ref |
| Determines whether the query is for a search. For more information on this and similar theme functions, check out the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags} article in the Theme Developer Handbook. return: bool Whether the query is for a search. |
| is_single( $post = '' ) X-Ref |
| Determines whether the query is for an existing single post. Works for any post type, except attachments and pages If the $post parameter is specified, this function will additionally check if the query is for one of the Posts specified. For more information on this and similar theme functions, check out the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags} article in the Theme Developer Handbook. param: int|string|int[]|string[] $post Optional. Post ID, title, slug, or array of such return: bool Whether the query is for an existing single post. |
| is_singular( $post_types = '' ) X-Ref |
| Determines whether the query is for an existing single post of any post type (post, attachment, page, custom post types). If the $post_types parameter is specified, this function will additionally check if the query is for one of the Posts Types specified. For more information on this and similar theme functions, check out the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags} article in the Theme Developer Handbook. param: string|string[] $post_types Optional. Post type or array of post types return: bool Whether the query is for an existing single post |
| is_time() X-Ref |
| Determines whether the query is for a specific time. For more information on this and similar theme functions, check out the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags} article in the Theme Developer Handbook. return: bool Whether the query is for a specific time. |
| is_trackback() X-Ref |
| Determines whether the query is for a trackback endpoint call. For more information on this and similar theme functions, check out the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags} article in the Theme Developer Handbook. return: bool Whether the query is for a trackback endpoint call. |
| is_year() X-Ref |
| Determines whether the query is for an existing year archive. For more information on this and similar theme functions, check out the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags} article in the Theme Developer Handbook. return: bool Whether the query is for an existing year archive. |
| is_404() X-Ref |
| Determines whether the query has resulted in a 404 (returns no results). For more information on this and similar theme functions, check out the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags} article in the Theme Developer Handbook. return: bool Whether the query is a 404 error. |
| is_embed() X-Ref |
| Is the query for an embedded post? return: bool Whether the query is for an embedded post. |
| is_main_query() X-Ref |
| Determines whether the query is the main query. For more information on this and similar theme functions, check out the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags} article in the Theme Developer Handbook. return: bool Whether the query is the main query. |
| have_posts() X-Ref |
| Determines whether current WordPress query has posts to loop over. return: bool True if posts are available, false if end of the loop. |
| in_the_loop() X-Ref |
| Determines whether the caller is in the Loop. For more information on this and similar theme functions, check out the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags} article in the Theme Developer Handbook. return: bool True if caller is within loop, false if loop hasn't started or ended. |
| rewind_posts() X-Ref |
| Rewind the loop posts. |
| the_post() X-Ref |
| Iterate the post index in the loop. |
| have_comments() X-Ref |
| Determines whether current WordPress query has comments to loop over. return: bool True if comments are available, false if no more comments. |
| the_comment() X-Ref |
| Iterate comment index in the comment loop. |
| wp_old_slug_redirect() X-Ref |
| Redirect old slugs to the correct permalink. Attempts to find the current slug from the past slugs. |
| _find_post_by_old_slug( $post_type ) X-Ref |
| Find the post ID for redirecting an old slug. param: string $post_type The current post type based on the query vars. return: int The Post ID. |
| _find_post_by_old_date( $post_type ) X-Ref |
| Find the post ID for redirecting an old date. param: string $post_type The current post type based on the query vars. return: int The Post ID. |
| wp_is_random_content_redirect_enabled() X-Ref |
| Determines whether random content redirects are enabled. return: bool True if random content redirects are enabled, false otherwise. |
| wp_is_random_content_query( WP_Query $query ) X-Ref |
| Determines whether a query is a request for random content. A random content request is a front end, main query for the blog home, an archive, or search results that includes the `random` query variable and at least one `randomable` post type. For example `example.com/random/`, `example.com/random/category/news/` or `example.com/?s=foo&random`. Singular (including embeds) and feed requests are never random content requests, nor are requests using an HTTP method other than GET or HEAD. param: WP_Query $query The query to check. return: bool True if the query is a request for random content, false otherwise. |
| wp_get_random_content_post_types( WP_Query $query ) X-Ref |
| Retrieves the post types eligible for selection by a random content request. These are the post types the query would otherwise return, limited to those registered as `randomable`. param: WP_Query $query The query to retrieve the post types for. return: string[] Post type names eligible for random selection. |
| wp_random_content_pre_get_posts( $query ) X-Ref |
| Limits the main query to posts eligible for random content requests. The main query is used to select the random post so the request runs the same query, and the same filters, as the archive it is randomizing. As such, callbacks on the {@see 'pre_get_posts'} action may modify the posts eligible for selection, for example to limit the post types or exclude a category: add_action( 'pre_get_posts', static function ( WP_Query $query ) { if ( wp_is_random_content_query( $query ) ) { $query->set( 'category__not_in', array( 1 ) ); } } ); Only randomable post types and published posts without a password are eligible. The number and order of posts are enforced by {@see wp_random_content_post_limits()} and {@see wp_random_content_posts_orderby()}, so callbacks modifying them on archives do not affect the selection. Added to the {@see 'pre_get_posts'} action by {@see WP::handle_random()} while the random content query runs, so it runs after other callbacks. param: WP_Query $query The WP_Query instance (passed by reference). |
| wp_random_content_posts_orderby( $orderby, WP_Query $query ) X-Ref |
| Orders the random content query randomly. Added to the {@see 'posts_orderby'} filter by {@see WP::handle_random()} while the random content query runs. Enforcing the order in SQL prevents {@see 'pre_get_posts'} callbacks setting the order of posts on archives from affecting the selection. param: string $orderby The ORDER BY clause of the query. param: WP_Query $query The WP_Query instance. return: string The ORDER BY clause of the query. |
| wp_random_content_post_limits( $limits, WP_Query $query ) X-Ref |
| Limits the random content query to a single post. Added to the {@see 'post_limits'} filter by {@see WP::handle_random()} while the random content query runs. Enforcing the limit in SQL prevents {@see 'pre_get_posts'} callbacks setting the number of posts, offset or page on archives from affecting the selection. param: string $limits The LIMIT clause of the query. param: WP_Query $query The WP_Query instance. return: string The LIMIT clause of the query. |
| wp_random_content_split_the_query( $split_the_query, WP_Query $query ) X-Ref |
| Prevents the random content query from being split into multiple database queries. Randomly ordered queries are not cached, so there is no benefit to querying the post IDs separately to the post objects. Disabling the split allows the random post to be retrieved in a single database query. param: bool $split_the_query Whether or not to split the query. param: WP_Query $query The WP_Query instance. return: bool Whether or not to split the query. |
| wp_random_content_redirect() X-Ref |
| Redirects random content requests to the randomly selected post. Called by {@see WP::handle_random()} immediately after the main query selects the random post, to avoid unnecessary processing before the redirect. As the redirect is sent before {@see WP::send_headers()}, the headers preventing the redirect being cached or indexed are sent with it. If no post is selected, for example on an empty archive, {@see WP::handle_random()} handles the request as a 404. If the post's permalink is on another site, the request is handled as a regular archive request. |
| wp_random_content_flush_rewrite_rules_for_post( int $post_id, WP_Post $post, bool $update = false, ?WP_Post $post_before = null ) X-Ref |
| Flushes the rewrite rules when a page or post at the random content base changes. A published page at the random base, for example `example.com/random/`, takes precedence over random content redirects. So does a published post when the permalink structure places posts at the same URL, for example `/%postname%/`, see {@see WP_Rewrite::post_permalinks_share_random_base()}. As the rewrite rules account for the page or post, they need to be regenerated when it is published, unpublished, renamed, moved or deleted. Runs on the {@see 'wp_after_insert_post'} and {@see 'after_delete_post'} actions. param: int $post_id Post ID. param: WP_Post $post Post object. param: bool $update Optional. Whether this is an existing post being updated. Default false. param: WP_Post|null $post_before Optional. Post object before the update, null for new posts. Default null. |
| setup_postdata( $post ) X-Ref |
| Set up global post data. param: WP_Post|object|int $post WP_Post instance or Post ID/object. return: bool True when finished. |
| generate_postdata( $post ) X-Ref |
| Generates post data. param: WP_Post|object|int $post WP_Post instance or Post ID/object. return: array|false Elements of post, or false on failure. |
| Generated : Tue Oct 20 08:20:34 2026 | Cross-referenced by PHPXref |