Title: WP_Privacy_Requests_Table::prepare_items
Published: October 5, 2018
Last modified: May 20, 2026

---

# WP_Privacy_Requests_Table::prepare_items()

## In this article

 * [Source](https://developer.wordpress.org/reference/classes/wp_privacy_requests_table/prepare_items/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_privacy_requests_table/prepare_items/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_privacy_requests_table/prepare_items/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_privacy_requests_table/prepare_items/?output_format=md#wp--skip-link--target)

Prepares items to output.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_privacy_requests_table/prepare_items/?output_format=md#source)󠁿

    ```php
    public function prepare_items() {
    	$this->items    = array();
    	$posts_per_page = $this->get_items_per_page( $this->request_type . '_requests_per_page' );
    	$args           = array(
    		'post_type'      => $this->post_type,
    		'post_name__in'  => array( $this->request_type ),
    		'posts_per_page' => $posts_per_page,
    		'offset'         => isset( $_REQUEST['paged'] ) ? max( 0, absint( $_REQUEST['paged'] ) - 1 ) * $posts_per_page : 0,
    		'post_status'    => 'any',
    		's'              => isset( $_REQUEST['s'] ) ? sanitize_text_field( $_REQUEST['s'] ) : '',
    	);

    	$orderby_mapping = array(
    		'requester' => 'post_title',
    		'requested' => 'post_date',
    	);

    	if ( isset( $_REQUEST['orderby'] ) && isset( $orderby_mapping[ $_REQUEST['orderby'] ] ) ) {
    		$args['orderby'] = $orderby_mapping[ $_REQUEST['orderby'] ];
    	}

    	if ( isset( $_REQUEST['order'] ) && in_array( strtoupper( $_REQUEST['order'] ), array( 'ASC', 'DESC' ), true ) ) {
    		$args['order'] = strtoupper( $_REQUEST['order'] );
    	}

    	if ( ! empty( $_REQUEST['filter-status'] ) ) {
    		$filter_status       = isset( $_REQUEST['filter-status'] ) ? sanitize_text_field( $_REQUEST['filter-status'] ) : '';
    		$args['post_status'] = $filter_status;
    	}

    	$requests_query = new WP_Query( $args );
    	$requests       = $requests_query->posts;

    	foreach ( $requests as $request ) {
    		$this->items[] = wp_get_user_request( $request->ID );
    	}

    	$this->items = array_filter( $this->items );

    	$this->set_pagination_args(
    		array(
    			'total_items' => $requests_query->found_posts,
    			'per_page'    => $posts_per_page,
    		)
    	);
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-privacy-requests-table.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-admin/includes/class-wp-privacy-requests-table.php#L367)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-admin/includes/class-wp-privacy-requests-table.php#L367-L412)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_privacy_requests_table/prepare_items/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_get_user_request()](https://developer.wordpress.org/reference/functions/wp_get_user_request/)`wp-includes/user.php` |

Returns the user request object for the specified request ID.

  | 
| [WP_Query::__construct()](https://developer.wordpress.org/reference/classes/wp_query/__construct/)`wp-includes/class-wp-query.php` |

Constructor.

  | 
| [sanitize_text_field()](https://developer.wordpress.org/reference/functions/sanitize_text_field/)`wp-includes/formatting.php` |

Sanitizes a string from user input or from the database.

  | 
| [absint()](https://developer.wordpress.org/reference/functions/absint/)`wp-includes/load.php` |

Converts a value to non-negative integer.

  |

[Show 2 more](https://developer.wordpress.org/reference/classes/wp_privacy_requests_table/prepare_items/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_privacy_requests_table/prepare_items/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_privacy_requests_table/prepare_items/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.1.0](https://developer.wordpress.org/reference/since/5.1.0/) | Added support for column sorting. | 
| [4.9.6](https://developer.wordpress.org/reference/since/4.9.6/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_privacy_requests_table%2Fprepare_items%2F)
before being able to contribute a note or feedback.