WordPress.org

Make WordPress Core

Changeset 49700


Ignore:
Timestamp:
11/26/2020 05:02:02 PM (5 months ago)
Author:
johnbillion
Message:

Docs: Corrections and improvements to docs for properties of the WP_Query class.

This also adds additional type hinting inside some methods to help IDEs.

See #51800

File:
1 edited

Legend:

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

    r49693 r49700  
    7777
    7878    /**
    79      * Get post database query.
     79     * SQL for the database query.
    8080     *
    8181     * @since 2.0.1
     
    8585
    8686    /**
    87      * List of posts.
     87     * Array of post objects or post IDs.
    8888     *
    8989     * @since 1.5.0
    90      * @var array
     90     * @var WP_Post[]|int[]
    9191     */
    9292    public $posts;
     
    119119     * The current post.
    120120     *
     121     * This property does not get populated when the `fields` argument is set to
     122     * `ids` or `id=>parent`.
     123     *
    121124     * @since 1.5.0
    122      * @var WP_Post
     125     * @var WP_Post|null
    123126     */
    124127    public $post;
     
    128131     *
    129132     * @since 2.2.0
    130      * @var array
     133     * @var WP_Comment[]
    131134     */
    132135    public $comments;
     
    149152
    150153    /**
    151      * Current comment ID.
     154     * Current comment object.
    152155     *
    153156     * @since 2.2.0
    154      * @var int
     157     * @var WP_Comment
    155158     */
    156159    public $comment;
     
    26612664            $comments = (array) $wpdb->get_results( "SELECT $distinct {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits" );
    26622665            // Convert to WP_Comment.
     2666            /** @var WP_Comment[] */
    26632667            $this->comments      = array_map( 'get_comment', $comments );
    26642668            $this->comment_count = count( $this->comments );
     
    29452949         * @since 4.6.0
    29462950         *
    2947          * @param array|null $posts Return an array of post data to short-circuit WP's query,
    2948          *                          or null to allow WP to run its normal queries.
    2949          * @param WP_Query   $this  The WP_Query instance (passed by reference).
     2951         * @param WP_Post[]|int[]|null $posts Return an array of post data to short-circuit WP's query,
     2952         *                                    or null to allow WP to run its normal queries.
     2953         * @param WP_Query             $this  The WP_Query instance (passed by reference).
    29502954         */
    29512955        $this->posts = apply_filters_ref_array( 'posts_pre_query', array( null, &$this ) );
     
    29562960            }
    29572961
     2962            /** @var int[] */
    29582963            $this->posts      = array_map( 'intval', $this->posts );
    29592964            $this->post_count = count( $this->posts );
     
    29712976            $this->set_found_posts( $q, $limits );
    29722977
     2978            /** @var int[] */
    29732979            $r = array();
    29742980            foreach ( $this->posts as $key => $post ) {
     
    30313037        // Convert to WP_Post objects.
    30323038        if ( $this->posts ) {
     3039            /** @var WP_Post[] */
    30333040            $this->posts = array_map( 'get_post', $this->posts );
    30343041        }
     
    30673074            $comments         = $wpdb->get_results( $comments_request );
    30683075            // Convert to WP_Comment.
     3076            /** @var WP_Comment[] */
    30693077            $this->comments      = array_map( 'get_comment', $comments );
    30703078            $this->comment_count = count( $this->comments );
     
    31963204            $this->post_count = count( $this->posts );
    31973205
     3206            /** @var WP_Post[] */
    31983207            $this->posts = array_map( 'get_post', $this->posts );
    31993208
     
    32023211            }
    32033212
     3213            /** @var WP_Post */
    32043214            $this->post = reset( $this->posts );
    32053215        } else {
     
    32823292        $this->current_post++;
    32833293
     3294        /** @var WP_Post */
    32843295        $this->post = $this->posts[ $this->current_post ];
    32853296        return $this->post;
     
    33753386        $this->current_comment++;
    33763387
     3388        /** @var WP_Comment */
    33773389        $this->comment = $this->comments[ $this->current_comment ];
    33783390        return $this->comment;
Note: See TracChangeset for help on using the changeset viewer.