update_post_parent_caches example

$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;
            }

            $data    = $this->prepare_item_for_response( $post$request );
            

    $query             = apply_filters( 'ajax_query_attachments_args', $query );
    $attachments_query = new WP_Query( $query );
    update_post_parent_caches( $attachments_query->posts );

    $posts       = array_map( 'wp_prepare_attachment_for_js', $attachments_query->posts );
    $posts       = array_filter( $posts );
    $total_posts = $attachments_query->found_posts;

    if ( $total_posts < 1 ) {
        // Out-of-bounds, run the query again without LIMIT for total count.         unset( $query['paged'] );

        $count_query = new WP_Query();
        $count_query->query( $query );
        
$this->is_trash = isset( $_REQUEST['attachment-filter'] ) && 'trash' === $_REQUEST['attachment-filter'];

        $this->set_pagination_args(
            array(
                'total_items' => $wp_query->found_posts,
                'total_pages' => $wp_query->max_num_pages,
                'per_page'    => $wp_query->query_vars['posts_per_page'],
            )
        );
        if ( $wp_query->posts ) {
            update_post_thumbnail_cache( $wp_query );
            update_post_parent_caches( $wp_query->posts );
        }
    }

    /** * @global array $post_mime_types * @global array $avail_post_mime_types * @return array */
    protected function get_views() {
        global $post_mime_types$avail_post_mime_types;

        
Home | Imprint | This part of the site doesn't use cookies.