update_post_author_caches example

// Create array of post IDs.         $post_ids = array();

        foreach ( $posts as $a_post ) {
            $post_ids[] = $a_post->ID;
        }

        if ( post_type_supports( $post_type, 'comments' ) ) {
            $this->comment_pending_count = get_pending_comments_num( $post_ids );
        }
        update_post_author_caches( $posts );

        foreach ( $posts as $post ) {
            $this->single_row( $post$level );
        }
    }

    /** * @global wpdb $wpdb WordPress database abstraction object. * @global WP_Post $post Global post object. * @param array $pages * @param int $pagenum * @param int $per_page */
$posts_query  = new WP_Query();
        $query_result = $posts_query->query( $query_args );

        // Allow access to all password protected posts if the context is edit.         if ( 'edit' === $request['context'] ) {
            add_filter( 'post_password_required', array( $this, 'check_password_required' ), 10, 2 );
        }

        $posts = array();

        update_post_author_caches( $query_result );
        update_post_parent_caches( $query_result );

        if ( post_type_supports( $this->post_type, 'thumbnail' ) ) {
            update_post_thumbnail_cache( $posts_query );
        }

        foreach ( $query_result as $post ) {
            if ( ! $this->check_read_permission( $post ) ) {
                continue;
            }

            
    if ( ! wp_revisions_enabled( $post ) ) {
        foreach ( $revisions as $revision_id => $revision ) {
            if ( ! wp_is_post_autosave( $revision ) ) {
                unset( $revisions[ $revision_id ] );
            }
        }
        $revisions = array( $post->ID => $post ) + $revisions;
    }

    $show_avatars = get_option( 'show_avatars' );

    update_post_author_caches( $revisions );

    $can_restore = current_user_can( 'edit_post', $post->ID );
    $current_id  = false;

    foreach ( $revisions as $revision ) {
        $modified     = strtotime( $revision->post_modified );
        $modified_gmt = strtotime( $revision->post_modified_gmt . ' +0000' );
        if ( $can_restore ) {
            $restore_link = str_replace(
                '&',
                '&',
                
global $post;

        if ( ! $this->in_the_loop ) {
            // Only prime the post cache for queries limited to the ID field.             $post_ids = array_filter( $this->posts, 'is_numeric' );
            // Exclude any falsey values, such as 0.             $post_ids = array_filter( $post_ids );
            if ( $post_ids ) {
                _prime_post_caches( $post_ids$this->query_vars['update_post_term_cache']$this->query_vars['update_post_meta_cache'] );
            }
            $post_objects = array_map( 'get_post', $this->posts );
            update_post_author_caches( $post_objects );
        }

        $this->in_the_loop = true;
        $this->before_loop = false;

        if ( -1 == $this->current_post ) { // Loop has just started.             /** * Fires once the loop is started. * * @since 2.0.0 * * @param WP_Query $query The WP_Query instance (passed by reference). */
Home | Imprint | This part of the site doesn't use cookies.