wppaste
WordPress

_WP_Editors::wp_link_query( array $args = array() ): array|false

Since
3.1.0
Source
wp-includes/class-wp-editor.php:1781
Performs post queries for internal linking.

Compatibility

WordPress
since 3.1.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

$argsarrayoptional
Array of link query arguments.Default: array()
  • $pagenumintdefault: 1

    Page number.
  • $sstring

    Search keywords.

Return value

array|false
$results { An array of associative arrays of query results, false if there are none.
  • ...$0array

    @type int $ID Post ID.
    • $titlestring

      The trimmed, escaped post title.
    • $permalinkstring

      Post permalink.
    • $infostring

      A 'Y/m/d'-formatted date for 'post' post type, the 'singular_name' post type label otherwise.

Performance profile

How much work a call to _WP_Editors::wp_link_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
Heavy

Reaches the database via ->query().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
54–67

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

Plugin surface
2 hooks

Third-party callbacks on 'wp_link_query_args', 'wp_link_query' 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
  • sqldatabase query->query()called directly
  • querycontent queryget_post()one call below _WP_Editors::wp_link_query()
  • optionoption read or writeget_option()one call below _WP_Editors::wp_link_query()

Further down the call graph this can also reach cache, serialize 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 · 2 distinct outcomes

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

WhenInstructionsCalls it makes
!isset($args)54–61get_post_types(), array_keys(), apply_filters(), post_type(), ->query(), apply_filters()
isset($args)60–67get_post_types(), array_keys(), absint(), apply_filters(), post_type(), ->query(), apply_filters()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev11154–6671 fewer instruction than PHP 8.5
8.511254–677
8.411254–6772 fewer instructions than PHP 8.3
8.311454–677
8.211454–677
8.111454–6771 fewer instruction than PHP 7.4
7.411554–687

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_Editors::wp_link_query() runs, in this order:

  1. apply_filters( wp_link_query_args )filterline 1813 (+32 into the body)

    Filters the link query arguments.

  2. apply_filters( wp_link_query )filterline 1858 (+77 into the body)

    Filters the link query results.

Uses · 9

Used by · 1

Source code

	public static function wp_link_query( $args = array() ) {		$pts      = get_post_types( array( 'public' => true ), 'objects' );		$pt_names = array_keys( $pts ); 		$query = array(			'post_type'              => $pt_names,			'suppress_filters'       => true,			'update_post_term_cache' => false,			'update_post_meta_cache' => false,			'post_status'            => 'publish',			'posts_per_page'         => 20,		); 		$args['pagenum'] = isset( $args['pagenum'] ) ? absint( $args['pagenum'] ) : 1; 		if ( isset( $args['s'] ) ) {			$query['s'] = $args['s'];		} 		$query['offset'] = $args['pagenum'] > 1 ? $query['posts_per_page'] * ( $args['pagenum'] - 1 ) : 0; 		/**		 * Filters the link query arguments.		 *		 * Allows modification of the link query arguments before querying.		 *		 * @see WP_Query for a full list of arguments		 *		 * @since 3.7.0		 *		 * @param array $query An array of WP_Query arguments.		 */		$query = apply_filters( 'wp_link_query_args', $query ); 		// Do main query.		$get_posts = new WP_Query();		$posts     = $get_posts->query( $query ); 		// Build results.		$results = array();		foreach ( $posts as $post ) {			if ( 'post' === $post->post_type ) {				$info = mysql2date( __( 'Y/m/d' ), $post->post_date );			} else {				$info = $pts[ $post->post_type ]->labels->singular_name;			} 			$results[] = array(				'ID'        => $post->ID,				'title'     => trim( esc_html( strip_tags( get_the_title( $post ) ) ) ),				'permalink' => get_permalink( $post->ID ),				'info'      => $info,			);		} 		/**		 * Filters the link query results.		 *		 * Allows modification of the returned link query results.		 *		 * @since 3.7.0		 *		 * @see 'wp_link_query_args' filter		 *		 * @param array $results {		 *     An array of associative arrays of query results.		 *		 *     @type array ...$0 {		 *         @type int    $ID        Post ID.		 *         @type string $title     The trimmed, escaped post title.		 *         @type string $permalink Post permalink.		 *         @type string $info      A 'Y/m/d'-formatted date for 'post' post type,		 *                                 the 'singular_name' post type label otherwise.		 *     }		 * }		 * @param array $query  An array of WP_Query arguments.		 */		$results = apply_filters( 'wp_link_query', $results, $query ); 		return ! empty( $results ) ? $results : false;

Changelog

Introduced in 3.1.0. Unchanged from 6.7.7 through 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.

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-includes/class-wp-editor.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.