_WP_Editors::wp_link_query( array $args = array() ): array|false
- Since
- 3.1.0
- Source
wp-includes/class-wp-editor.php:1781
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: 1Page number.$sstringSearch 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.$titlestringThe trimmed, escaped post title.$permalinkstringPost permalink.$infostringA '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
- Scaling
- Scales with input
- Instructions
- 54–67
- Plugin surface
- 2 hooks
- Called by
- 1
Reaches the database via ->query().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 112.
Third-party callbacks on 'wp_link_query_args', 'wp_link_query' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - sqldatabase query
->query()called directly - querycontent query
get_post()one call below _WP_Editors::wp_link_query() - optionoption read or write
get_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.
| When | Instructions | Calls it makes |
|---|---|---|
!isset($args) | 54–61 | get_post_types(), array_keys(), apply_filters(), post_type(), ->query(), apply_filters() |
isset($args) | 60–67 | get_post_types(), array_keys(), absint(), apply_filters(), post_type(), ->query(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 111 | 54–66 | 7 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 112 | 54–67 | 7 | |
| 8.4 | 112 | 54–67 | 7 | 2 fewer instructions than PHP 8.3 |
| 8.3 | 114 | 54–67 | 7 | |
| 8.2 | 114 | 54–67 | 7 | |
| 8.1 | 114 | 54–67 | 7 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 115 | 54–68 | 7 |
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:
- apply_filters( wp_link_query_args )filterline 1813 (+32 into the body)
Filters the link query arguments.
Uses · 9
- get_post_types()Gets a list of all registered post type objects.
- absint()Converts a value to non-negative integer.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- mysql2date()Converts given MySQL date string into a different format.
- __()Retrieves the translation of $text.
- esc_html()Escaping for HTML blocks.
- get_the_title()Retrieves the post title.
- get_permalink()Retrieves the full permalink for the current post or post ID.
- WP_Query::__construct()Constructor.
Used by · 1
- wp_ajax_wp_link_ajax()Handles internal linking via AJAX.
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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 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.