Make WordPress Core


Ignore:
Timestamp:
11/20/2021 12:06:06 AM (5 years ago)
Author:
johnbillion
Message:

Query: Correct and standardise the meta query documentation.

Also improves the formatting of some surrounding documentation.

Props audrasjb, johnbillion

Fixes #53467

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-term-query.php

    r51518 r52226  
    8989         * @since 4.7.0 Introduced 'object_ids' parameter.
    9090         * @since 4.9.0 Added 'slug__in' support for 'orderby'.
     91         * @since 5.1.0 Introduced the 'meta_compare_key' parameter.
     92         * @since 5.3.0 Introduced the 'meta_type_key' parameter.
    9193         *
    9294         * @param string|array $query {
    9395         *     Optional. Array or query string of term query parameters. Default empty.
    9496         *
    95          *     @type string|array $taxonomy               Taxonomy name, or array of taxonomies, to which results should
    96          *                                                be limited.
    97          *     @type int|int[]    $object_ids             Object ID, or array of object IDs. Results will be
    98          *                                                limited to terms associated with these objects.
    99          *     @type string       $orderby                Field(s) to order terms by. Accepts:
    100          *                                                * Term fields ('name', 'slug', 'term_group', 'term_id', 'id',
    101          *                                                  'description', 'parent', 'term_order'). Unless `$object_ids`
    102          *                                                  is not empty, 'term_order' is treated the same as 'term_id'.
    103          *                                                * 'count' to use the number of objects associated with the term.
    104          *                                                * 'include' to match the 'order' of the `$include` param.
    105          *                                                * 'slug__in' to match the 'order' of the `$slug` param.
    106          *                                                * 'meta_value'
    107          *                                                * 'meta_value_num'.
    108          *                                                * The value of `$meta_key`.
    109          *                                                * The array keys of `$meta_query`.
    110          *                                                * 'none' to omit the ORDER BY clause.
    111          *                                                Default 'name'.
    112          *     @type string       $order                  Whether to order terms in ascending or descending order.
    113          *                                                Accepts 'ASC' (ascending) or 'DESC' (descending).
    114          *                                                Default 'ASC'.
    115          *     @type bool|int     $hide_empty             Whether to hide terms not assigned to any posts. Accepts
    116          *                                                1|true or 0|false. Default 1|true.
    117          *     @type int[]|string $include                Array or comma/space-separated string of term IDs to include.
    118          *                                                Default empty array.
    119          *     @type int[]|string $exclude                Array or comma/space-separated string of term IDs to exclude.
    120          *                                                If `$include` is non-empty, `$exclude` is ignored.
    121          *                                                Default empty array.
    122          *     @type int[]|string $exclude_tree           Array or comma/space-separated string of term IDs to exclude
    123          *                                                along with all of their descendant terms. If `$include` is
    124          *                                                non-empty, `$exclude_tree` is ignored. Default empty array.
    125          *     @type int|string   $number                 Maximum number of terms to return. Accepts ''|0 (all) or any
    126          *                                                positive number. Default ''|0 (all). Note that $number may
    127          *                                                not return accurate results when coupled with `$object_ids`.
    128          *                                                See #41796 for details.
    129          *     @type int          $offset                 The number by which to offset the terms query. Default empty.
    130          *     @type string       $fields                 Term fields to query for. Accepts:
    131          *                                                * 'all' Returns an array of complete term objects (`WP_Term[]`).
    132          *                                                * 'all_with_object_id' Returns an array of term objects
    133          *                                                  with the 'object_id' param (`WP_Term[]`). Works only
    134          *                                                  when the `$object_ids` parameter is populated.
    135          *                                                * 'ids' Returns an array of term IDs (`int[]`).
    136          *                                                * 'tt_ids' Returns an array of term taxonomy IDs (`int[]`).
    137          *                                                * 'names' Returns an array of term names (`string[]`).
    138          *                                                * 'slugs' Returns an array of term slugs (`string[]`).
    139          *                                                * 'count' Returns the number of matching terms (`int`).
    140          *                                                * 'id=>parent' Returns an associative array of parent term IDs,
    141          *                                                   keyed by term ID (`int[]`).
    142          *                                                * 'id=>name' Returns an associative array of term names,
    143          *                                                   keyed by term ID (`string[]`).
    144          *                                                * 'id=>slug' Returns an associative array of term slugs,
    145          *                                                   keyed by term ID (`string[]`).
    146          *                                                Default 'all'.
    147          *     @type bool         $count                  Whether to return a term count. If true, will take precedence
    148          *                                                over `$fields`. Default false.
    149          *     @type string|array $name                   Name or array of names to return term(s) for.
    150          *                                                Default empty.
    151          *     @type string|array $slug                   Slug or array of slugs to return term(s) for.
    152          *                                                Default empty.
    153          *     @type int|int[]    $term_taxonomy_id       Term taxonomy ID, or array of term taxonomy IDs,
    154          *                                                to match when querying terms.
    155          *     @type bool         $hierarchical           Whether to include terms that have non-empty descendants
    156          *                                                (even if `$hide_empty` is set to true). Default true.
    157          *     @type string       $search                 Search criteria to match terms. Will be SQL-formatted with
    158          *                                                wildcards before and after. Default empty.
    159          *     @type string       $name__like             Retrieve terms with criteria by which a term is LIKE
    160          *                                                `$name__like`. Default empty.
    161          *     @type string       $description__like      Retrieve terms where the description is LIKE
    162          *                                                `$description__like`. Default empty.
    163          *     @type bool         $pad_counts             Whether to pad the quantity of a term's children in the
    164          *                                                quantity of each term's "count" object variable.
    165          *                                                Default false.
    166          *     @type string       $get                    Whether to return terms regardless of ancestry or whether the
    167          *                                                terms are empty. Accepts 'all' or '' (disabled).
    168          *                                                Default ''.
    169          *     @type int          $child_of               Term ID to retrieve child terms of. If multiple taxonomies
    170          *                                                are passed, `$child_of` is ignored. Default 0.
    171          *     @type int          $parent                 Parent term ID to retrieve direct-child terms of.
    172          *                                                Default empty.
    173          *     @type bool         $childless              True to limit results to terms that have no children.
    174          *                                                This parameter has no effect on non-hierarchical taxonomies.
    175          *                                                Default false.
    176          *     @type string       $cache_domain           Unique cache key to be produced when this query is stored in
    177          *                                                an object cache. Default 'core'.
    178          *     @type bool         $update_term_meta_cache Whether to prime meta caches for matched terms. Default true.
    179          *     @type array        $meta_query             Meta query clauses to limit retrieved terms by.
    180          *                                                See `WP_Meta_Query`. Default empty.
    181          *     @type string       $meta_key               Limit terms to those matching a specific metadata key.
    182          *                                                Can be used in conjunction with `$meta_value`. Default empty.
    183          *     @type string       $meta_value             Limit terms to those matching a specific metadata value.
    184          *                                                Usually used in conjunction with `$meta_key`. Default empty.
    185          *     @type string       $meta_type              MySQL data type that the `$meta_value` will be CAST to for
    186          *                                                comparisons. Default empty.
    187          *     @type string       $meta_compare           Comparison operator to test the 'meta_value'. Default empty.
     97         *     @type string|array    $taxonomy               Taxonomy name, or array of taxonomies, to which results should
     98         *                                                   be limited.
     99         *     @type int|int[]       $object_ids             Object ID, or array of object IDs. Results will be
     100         *                                                   limited to terms associated with these objects.
     101         *     @type string          $orderby                Field(s) to order terms by. Accepts:
     102         *                                                   - Term fields ('name', 'slug', 'term_group', 'term_id', 'id',
     103         *                                                     'description', 'parent', 'term_order'). Unless `$object_ids`
     104         *                                                     is not empty, 'term_order' is treated the same as 'term_id'.
     105         *                                                   - 'count' to use the number of objects associated with the term.
     106         *                                                   - 'include' to match the 'order' of the `$include` param.
     107         *                                                   - 'slug__in' to match the 'order' of the `$slug` param.
     108         *                                                   - 'meta_value'
     109         *                                                   - 'meta_value_num'.
     110         *                                                   - The value of `$meta_key`.
     111         *                                                   - The array keys of `$meta_query`.
     112         *                                                   - 'none' to omit the ORDER BY clause.
     113         *                                                   Default 'name'.
     114         *     @type string          $order                  Whether to order terms in ascending or descending order.
     115         *                                                   Accepts 'ASC' (ascending) or 'DESC' (descending).
     116         *                                                   Default 'ASC'.
     117         *     @type bool|int        $hide_empty             Whether to hide terms not assigned to any posts. Accepts
     118         *                                                   1|true or 0|false. Default 1|true.
     119         *     @type int[]|string    $include                Array or comma/space-separated string of term IDs to include.
     120         *                                                   Default empty array.
     121         *     @type int[]|string    $exclude                Array or comma/space-separated string of term IDs to exclude.
     122         *                                                   If `$include` is non-empty, `$exclude` is ignored.
     123         *                                                   Default empty array.
     124         *     @type int[]|string    $exclude_tree           Array or comma/space-separated string of term IDs to exclude
     125         *                                                   along with all of their descendant terms. If `$include` is
     126         *                                                   non-empty, `$exclude_tree` is ignored. Default empty array.
     127         *     @type int|string      $number                 Maximum number of terms to return. Accepts ''|0 (all) or any
     128         *                                                   positive number. Default ''|0 (all). Note that `$number` may
     129         *                                                   not return accurate results when coupled with `$object_ids`.
     130         *                                                   See #41796 for details.
     131         *     @type int             $offset                 The number by which to offset the terms query. Default empty.
     132         *     @type string          $fields                 Term fields to query for. Accepts:
     133         *                                                   - 'all' Returns an array of complete term objects (`WP_Term[]`).
     134         *                                                   - 'all_with_object_id' Returns an array of term objects
     135         *                                                     with the 'object_id' param (`WP_Term[]`). Works only
     136         *                                                     when the `$object_ids` parameter is populated.
     137         *                                                   - 'ids' Returns an array of term IDs (`int[]`).
     138         *                                                   - 'tt_ids' Returns an array of term taxonomy IDs (`int[]`).
     139         *                                                   - 'names' Returns an array of term names (`string[]`).
     140         *                                                   - 'slugs' Returns an array of term slugs (`string[]`).
     141         *                                                   - 'count' Returns the number of matching terms (`int`).
     142         *                                                   - 'id=>parent' Returns an associative array of parent term IDs,
     143         *                                                      keyed by term ID (`int[]`).
     144         *                                                   - 'id=>name' Returns an associative array of term names,
     145         *                                                      keyed by term ID (`string[]`).
     146         *                                                   - 'id=>slug' Returns an associative array of term slugs,
     147         *                                                      keyed by term ID (`string[]`).
     148         *                                                   Default 'all'.
     149         *     @type bool            $count                  Whether to return a term count. If true, will take precedence
     150         *                                                   over `$fields`. Default false.
     151         *     @type string|array    $name                   Name or array of names to return term(s) for.
     152         *                                                   Default empty.
     153         *     @type string|array    $slug                   Slug or array of slugs to return term(s) for.
     154         *                                                   Default empty.
     155         *     @type int|int[]       $term_taxonomy_id       Term taxonomy ID, or array of term taxonomy IDs,
     156         *                                                   to match when querying terms.
     157         *     @type bool            $hierarchical           Whether to include terms that have non-empty descendants
     158         *                                                   (even if `$hide_empty` is set to true). Default true.
     159         *     @type string          $search                 Search criteria to match terms. Will be SQL-formatted with
     160         *                                                   wildcards before and after. Default empty.
     161         *     @type string          $name__like             Retrieve terms with criteria by which a term is LIKE
     162         *                                                   `$name__like`. Default empty.
     163         *     @type string          $description__like      Retrieve terms where the description is LIKE
     164         *                                                   `$description__like`. Default empty.
     165         *     @type bool            $pad_counts             Whether to pad the quantity of a term's children in the
     166         *                                                   quantity of each term's "count" object variable.
     167         *                                                   Default false.
     168         *     @type string          $get                    Whether to return terms regardless of ancestry or whether the
     169         *                                                   terms are empty. Accepts 'all' or '' (disabled).
     170         *                                                   Default ''.
     171         *     @type int             $child_of               Term ID to retrieve child terms of. If multiple taxonomies
     172         *                                                   are passed, `$child_of` is ignored. Default 0.
     173         *     @type int             $parent                 Parent term ID to retrieve direct-child terms of.
     174         *                                                   Default empty.
     175         *     @type bool            $childless              True to limit results to terms that have no children.
     176         *                                                   This parameter has no effect on non-hierarchical taxonomies.
     177         *                                                   Default false.
     178         *     @type string          $cache_domain           Unique cache key to be produced when this query is stored in
     179         *                                                   an object cache. Default 'core'.
     180         *     @type bool            $update_term_meta_cache Whether to prime meta caches for matched terms. Default true.
     181         *     @type string|string[] $meta_key               Meta key or keys to filter by.
     182         *     @type string|string[] $meta_value             Meta value or values to filter by.
     183         *     @type string          $meta_compare           MySQL operator used for comparing the meta value.
     184         *                                                   See WP_Meta_Query::__construct for accepted values and default value.
     185         *     @type string          $meta_compare_key       MySQL operator used for comparing the meta key.
     186         *                                                   See WP_Meta_Query::__construct for accepted values and default value.
     187         *     @type string          $meta_type              MySQL data type that the meta_value column will be CAST to for comparisons.
     188         *                                                   See WP_Meta_Query::__construct for accepted values and default value.
     189         *     @type string          $meta_type_key          MySQL data type that the meta_key column will be CAST to for comparisons.
     190         *                                                   See WP_Meta_Query::__construct for accepted values and default value.
     191         *     @type array           $meta_query             An associative array of WP_Meta_Query arguments.
     192         *                                                   See WP_Meta_Query::__construct for accepted values.
    188193         * }
    189194         */
Note: See TracChangeset for help on using the changeset viewer.