WP_Query::parse_query() – Parse a query string and set query type booleans.

You appear to be a bot. Output may be restricted

Description

Parse a query string and set query type booleans.

Usage

WP_Query::parse_query( $query );

Parameters

$query
( string|array ) optional – { Optional. Array or string of Query parameters.
$attachment_id
( int ) optional – Attachment post ID. Used for 'attachment' post_type.
$author
( int|string ) optional – Author ID, or comma-separated list of IDs.
$author_name
( string ) optional – User 'user_nicename'.
$author__in
( int[] ) optional – An array of author IDs to query from.
$author__not_in
( int[] ) optional – An array of author IDs not to query from.
$cache_results
( bool ) optional – Whether to cache post information. Default true.
$cat
( int|string ) optional – Category ID or comma-separated list of IDs (this or any children).
$category__and
( int[] ) optional – An array of category IDs (AND in).
$category__in
( int[] ) optional – An array of category IDs (OR in, no children).
$category__not_in
( int[] ) optional – An array of category IDs (NOT in).
$category_name
( string ) optional – Use category slug (not name, this or any children).
$comment_count
( array|int ) optional – Filter results by comment count. Provide an integer to match comment count exactly. Provide an array with integer 'value' and 'compare' operator ('=', '!=', '>', '>=', '<', '<=' ) to compare against comment_count in a specific way.
$comment_status
( string ) optional – Comment status.
$comments_per_page
( int ) optional – The number of comments to return per page. Default 'comments_per_page' option.
$date_query
( array ) optional – An associative array of WP_Date_Query arguments. See WP_Date_Query::__construct().
$day
( int ) optional – Day of the month. Default empty. Accepts numbers 1-31.
$exact
( bool ) optional – Whether to search by exact keyword. Default false.
$fields
( string ) optional – Post fields to query for. Accepts:

  • '' Returns an array of complete post objects (`WP_Post[]`).
  • 'ids' Returns an array of post IDs (`int[]`).
  • 'id=>parent' Returns an associative array of parent post IDs,

keyed by post ID (`int[]`). Default ''.

$hour
( int ) optional – Hour of the day. Default empty. Accepts numbers 0-23.
$ignore_sticky_posts
( int|bool ) optional – Whether to ignore sticky posts or not. Setting this to false excludes stickies from 'post__in'. Accepts 1|true, 0|false. Default false.
$m
( int ) optional – Combination YearMonth. Accepts any four-digit year and month numbers 1-12. Default empty.
$meta_key
( string|string[] ) optional – Meta key or keys to filter by.
$meta_value
( string|string[] ) optional – Meta value or values to filter by.
$meta_compare
( string ) optional – MySQL operator used for comparing the meta value. See WP_Meta_Query::__construct for accepted values and default value.
$meta_compare_key
( string ) optional – MySQL operator used for comparing the meta key. See WP_Meta_Query::__construct for accepted values and default value.
$meta_type
( string ) optional – MySQL data type that the meta_value column will be CAST to for comparisons. See WP_Meta_Query::__construct for accepted values and default value.
$meta_type_key
( string ) optional – MySQL data type that the meta_key column will be CAST to for comparisons. See WP_Meta_Query::__construct for accepted values and default value.
$meta_query
( array ) optional – An associative array of WP_Meta_Query arguments. See WP_Meta_Query::__construct for accepted values.
$menu_order
( int ) optional – The menu order of the posts.
$minute
( int ) optional – Minute of the hour. Default empty. Accepts numbers 0-59.
$monthnum
( int ) optional – The two-digit month. Default empty. Accepts numbers 1-12.
$name
( string ) optional – Post slug.
$nopaging
( bool ) optional – Show all posts (true) or paginate (false). Default false.
$no_found_rows
( bool ) optional – Whether to skip counting the total rows found. Enabling can improve performance. Default false.
$offset
( int ) optional – The number of posts to offset before retrieval.
$order
( string ) optional – Designates ascending or descending order of posts. Default 'DESC'. Accepts 'ASC', 'DESC'.
$orderby
( string|array ) optional – Sort retrieved posts by parameter. One or more options may be passed. To use 'meta_value', or 'meta_value_num', 'meta_key=keyname' must be also be defined. To sort by a specific $meta_query clause, use that clause's array key. Accepts:

  • 'none'
  • 'name'
  • 'author'
  • 'date'
  • 'title'
  • 'modified'
  • 'menu_order'
  • 'parent'
  • 'ID'
  • 'rand'
  • 'relevance'
  • 'RAND(x)' (where 'x' is an integer seed value)
  • 'comment_count'
  • 'meta_value'
  • 'meta_value_num'
  • 'post__in'
  • 'post_name__in'
  • 'post_parent__in'
  • The array keys of `$meta_query`.

Default is 'date', except when a search is being performed, when the default is 'relevance'.

$p
( int ) optional – Post ID.
$page
( int ) optional – Show the number of posts that would show up on page X of a static front page.
$paged
( int ) optional – The number of the current page.
$page_id
( int ) optional – Page ID.
$pagename
( string ) optional – Page slug.
$perm
( string ) optional – Show posts if user has the appropriate capability.
$ping_status
( string ) optional – Ping status.
$post__in
( int[] ) optional – An array of post IDs to retrieve, sticky posts will be included.
$post__not_in
( int[] ) optional – An array of post IDs not to retrieve. Note: a string of comma- separated IDs will NOT work.
$post_mime_type
( string ) optional – The mime type of the post. Used for 'attachment' post_type.
$post_name__in
( string[] ) optional – An array of post slugs that results must match.
$post_parent
( int ) optional – Page ID to retrieve child pages for. Use 0 to only retrieve top-level pages.
$post_parent__in
( int[] ) optional – An array containing parent page IDs to query child pages from.
$post_parent__not_in
( int[] ) optional – An array containing parent page IDs not to query child pages from.
$post_type
( string|string[] ) optional – A post type slug (string) or array of post type slugs. Default 'any' if using 'tax_query'.
$post_status
( string|string[] ) optional – A post status (string) or array of post statuses.
$posts_per_page
( int ) optional – The number of posts to query for. Use -1 to request all posts.
$posts_per_archive_page
( int ) optional – The number of posts to query for by archive page. Overrides 'posts_per_page' when is_archive(), or is_search() are true.
$s
( string ) optional – Search keyword(s). Prepending a term with a hyphen will exclude posts matching that term. Eg, 'pillow -sofa' will return posts containing 'pillow' but not 'sofa'. The character used for exclusion can be modified using the the 'wp_query_search_exclusion_prefix' filter.
$second
( int ) optional – Second of the minute. Default empty. Accepts numbers 0-59.
$sentence
( bool ) optional – Whether to search by phrase. Default false.
$suppress_filters
( bool ) optional – Whether to suppress filters. Default false.
$tag
( string ) optional – Tag slug. Comma-separated (either), Plus-separated (all).
$tag__and
( int[] ) optional – An array of tag IDs (AND in).
$tag__in
( int[] ) optional – An array of tag IDs (OR in).
$tag__not_in
( int[] ) optional – An array of tag IDs (NOT in).
$tag_id
( int ) optional – Tag id or comma-separated list of IDs.
$tag_slug__and
( string[] ) optional – An array of tag slugs (AND in).
$tag_slug__in
( string[] ) optional – An array of tag slugs (OR in). unless 'ignore_sticky_posts' is true. Note: a string of comma-separated IDs will NOT work.
$tax_query
( array ) optional – An associative array of WP_Tax_Query arguments. See WP_Tax_Query->__construct().
$title
( string ) optional – Post title.
$update_post_meta_cache
( bool ) optional – Whether to update the post meta cache. Default true.
$update_post_term_cache
( bool ) optional – Whether to update the post term cache. Default true.
$lazy_load_term_meta
( bool ) optional – Whether to lazy-load term meta. Setting to false will disable cache priming for term meta, so that each get_term_meta() call will hit the database. Defaults to the value of `$update_post_term_cache`.
$w
( int ) optional – The week number of the year. Default empty. Accepts numbers 0-53.
$year
( int ) optional – The four-digit year. Default empty. Accepts any four-digit year. }

Returns

void

Source

File name: wordpress/wp-includes/class-wp-query.php
Lines:

1 to 100 of 339
  public function parse_query( $query = '' ) {
    if ( ! empty( $query ) ) {
      $this->WP_Query::init();
      $this->WP_Query::query      = wp_parse_args( $query );
      $this->query_vars = $this->WP_Query::query;
    } elseif ( ! isset( $this->WP_Query::query ) ) {
      $this->WP_Query::query = $this->query_vars;
    }

    $this->query_vars         = $this->WP_Query::fill_query_vars( $this->query_vars );
    $qv                       = &$this->query_vars;
    $this->query_vars_changed = true;

    if ( ! empty( $qv['robots'] ) ) {
      $this->WP_Query::is_robots = true;
    } elseif ( ! empty( $qv['favicon'] ) ) {
      $this->is_favicon = true;
    }

    if ( ! is_scalar( $qv['p'] ) || (int) $qv['p'] < 0 ) {
      $qv['p']     = 0;
      $qv['error'] = '404';
    } else {
      $qv['p'] = (int) $qv['p'];
    }

    $qv['page_id']  = absint( $qv['page_id'] );
    $qv['year']     = absint( $qv['year'] );
    $qv['monthnum'] = absint( $qv['monthnum'] );
    $qv['day']      = absint( $qv['day'] );
    $qv['w']        = absint( $qv['w'] );
    $qv['m']        = is_scalar( $qv['m'] ) ? preg_replace( '|[^0-9]|', '', $qv['m'] ) : '';
    $qv['paged']    = absint( $qv['paged'] );
    $qv['cat']      = preg_replace( '|[^0-9,-]|', '', $qv['cat'] );    // Comma-separated list of positive or negative integers.
    $qv['author']   = preg_replace( '|[^0-9,-]|', '', $qv['author'] ); // Comma-separated list of positive or negative integers.
    $qv['pagename'] = trim( $qv['pagename'] );
    $qv['name']     = trim( $qv['name'] );
    $qv['title']    = trim( $qv['title'] );
    if ( '' !== $qv['hour'] ) {
      $qv['hour'] = absint( $qv['hour'] );
    }
    if ( '' !== $qv['minute'] ) {
      $qv['minute'] = absint( $qv['minute'] );
    }
    if ( '' !== $qv['second'] ) {
      $qv['second'] = absint( $qv['second'] );
    }
    if ( '' !== $qv['menu_order'] ) {
      $qv['menu_order'] = absint( $qv['menu_order'] );
    }

    // Fairly large, potentially too large, upper bound for search string lengths.
    if ( ! is_scalar( $qv['s'] ) || ( ! empty( $qv['s'] ) && strlen( $qv['s'] ) > 1600 ) ) {
      $qv['s'] = '';
    }

    // Compat. Map subpost to attachment.
    if ( '' != $qv['subpost'] ) {
      $qv['attachment'] = $qv['subpost'];
    }
    if ( '' != $qv['subpost_id'] ) {
      $qv['attachment_id'] = $qv['subpost_id'];
    }

    $qv['attachment_id'] = absint( $qv['attachment_id'] );

    if ( ( '' !== $qv['attachment'] ) || ! empty( $qv['attachment_id'] ) ) {
      $this->WP_Query::is_single     = true;
      $this->WP_Query::is_attachment = true;
    } elseif ( '' !== $qv['name'] ) {
      $this->WP_Query::is_single = true;
    } elseif ( $qv['p'] ) {
      $this->WP_Query::is_single = true;
    } elseif ( '' !== $qv['pagename'] || ! empty( $qv['page_id'] ) ) {
      $this->WP_Query::is_page   = true;
      $this->WP_Query::is_single = false;
    } else {
      // Look for archive queries. Dates, categories, authors, search, post type archives.

      if ( isset( $this->WP_Query::query['s'] ) ) {
        $this->WP_Query::is_search = true;
      }

      if ( '' !== $qv['second'] ) {
        $this->WP_Query::is_time = true;
        $this->WP_Query::is_date = true;
      }

      if ( '' !== $qv['minute'] ) {
        $this->WP_Query::is_time = true;
        $this->WP_Query::is_date = true;
      }

      if ( '' !== $qv['hour'] ) {
        $this->WP_Query::is_time = true;
        $this->WP_Query::is_date = true;
      }

      if ( $qv['day'] ) {
        if ( ! $this->WP_Query::is_date ) {
 

 View on GitHub View on Trac