wppaste
WordPress

wp_edit_posts_query( array|false $q = false ): string[]

Since
2.5.0
Source
wp-admin/includes/post.php:1225
Runs the query to fetch the posts for listing on the edit posts page.

Compatibility

WordPress
since 2.5.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$qarray|falseoptional
Array of query variables to use to build the query.
Defaults to the $_GET superglobal.Default: false

Return value

string[]
An array of all the statuses for the queried post type.

Performance profile

How much work a call to wp_edit_posts_query() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Moderate

Reads stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
82–125

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 140.

Plugin surface
2 hooks

Third-party callbacks on 'edit_{$post_type}_per_page', 'edit_posts_per_page' run inside this call, and their cost is not bounded by anything here.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_filters()called directly
  • optionoption read or writeget_option()called directly
  • cacheobject cachewp_cache_get()one call below wp_edit_posts_query()
  • serializeserialisationmaybe_unserialize()one call below wp_edit_posts_query()

Further down the call graph this can also reach query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 4 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_edit_posts_query() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
$q !== false && !isset($q) && empty($q)82–113get_post_stati(), get_available_post_statuses(), get_user_option(), apply_filters(), apply_filters(), compact(), is_post_type_hierarchical(), wp()
$q !== false && !isset($q) && !empty($q)88–119get_post_stati(), get_available_post_statuses(), get_user_option(), apply_filters(), apply_filters(), compact(), is_post_type_hierarchical(), get_option(), wp()
$q !== false && empty($q)88–119get_post_stati(), get_post_types(), get_available_post_statuses(), get_user_option(), apply_filters(), apply_filters(), compact(), is_post_type_hierarchical(), wp()
$q !== false && !empty($q)94–125get_post_stati(), get_post_types(), get_available_post_statuses(), get_user_option(), apply_filters(), apply_filters(), compact(), is_post_type_hierarchical(), get_option(), wp()

This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev14082–12518
8.514082–12518
8.414082–125186 fewer instructions than PHP 8.3
8.314682–13118
8.214682–13118
8.114682–131182 fewer instructions than PHP 7.4
7.414882–13118

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 2

2 hooks fire while wp_edit_posts_query() runs, in this order:

  1. apply_filters( edit_{$post_type}_per_page )filterline 1288 (+63 into the body)

    Filters the number of items per page to show for a specific 'per_page' type.

  2. apply_filters( edit_posts_per_page )filterline 1298 (+73 into the body)

    Filters the number of posts displayed per page when specifically listing "posts".

Uses · 8

Used by · 1

Source code

function wp_edit_posts_query( $q = false ) {	if ( false === $q ) {		$q = $_GET;	} 	$q['m']   = isset( $q['m'] ) ? (int) $q['m'] : 0;	$q['cat'] = isset( $q['cat'] ) ? (int) $q['cat'] : 0; 	$post_statuses = get_post_stati(); 	if ( isset( $q['post_type'] ) && in_array( $q['post_type'], get_post_types(), true ) ) {		$post_type = $q['post_type'];	} else {		$post_type = 'post';	} 	$avail_post_stati = get_available_post_statuses( $post_type );	$post_status      = '';	$perm             = ''; 	if ( isset( $q['post_status'] ) && in_array( $q['post_status'], $post_statuses, true ) ) {		$post_status = $q['post_status'];		$perm        = 'readable';	} 	$orderby = ''; 	if ( isset( $q['orderby'] ) ) {		$orderby = $q['orderby'];	} elseif ( isset( $q['post_status'] ) && in_array( $q['post_status'], array( 'pending', 'draft' ), true ) ) {		$orderby = 'modified';	} 	$order = ''; 	if ( isset( $q['order'] ) ) {		$order = $q['order'];	} elseif ( isset( $q['post_status'] ) && 'pending' === $q['post_status'] ) {		$order = 'ASC';	} 	$per_page       = "edit_{$post_type}_per_page";	$posts_per_page = (int) get_user_option( $per_page );	if ( empty( $posts_per_page ) || $posts_per_page < 1 ) {		$posts_per_page = 20;	} 	/**	 * Filters the number of items per page to show for a specific 'per_page' type.	 *	 * The dynamic portion of the hook name, `$post_type`, refers to the post type.	 *	 * Possible hook names include:	 *	 *  - `edit_post_per_page`	 *  - `edit_page_per_page`	 *  - `edit_attachment_per_page`	 *	 * @since 3.0.0	 *	 * @param int $posts_per_page Number of posts to display per page for the given post	 *                            type. Default 20.	 */	$posts_per_page = apply_filters( "edit_{$post_type}_per_page", $posts_per_page ); 	/**	 * Filters the number of posts displayed per page when specifically listing "posts".	 *	 * @since 2.8.0	 *	 * @param int    $posts_per_page Number of posts to be displayed. Default 20.	 * @param string $post_type      The post type.	 */	$posts_per_page = apply_filters( 'edit_posts_per_page', $posts_per_page, $post_type ); 	$query = compact( 'post_type', 'post_status', 'perm', 'order', 'orderby', 'posts_per_page' ); 	// Hierarchical types require special args.	if ( is_post_type_hierarchical( $post_type ) && empty( $orderby ) ) {		$query['orderby']                = 'menu_order title';

Changelog

Introduced in 2.5.0. One change between 6.7.7 and 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

6.8.8
Return type changed from array to string[].verified against source
2.5.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-admin/includes/post.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.