• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress core a2z

WordPress core a2z

WordPress core only

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / _WP_Editors::wp_link_query() – Performs post queries for internal linking.

You appear to be a bot. Output may be restricted

Description

Performs post queries for internal linking.

Usage

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

Parameters

$args
( array ) optional – Optional. Accepts 'pagenum' and 's' (search) arguments.

Returns

array|false Results.

Source

File name: wordpress/wp-includes/class-wp-editor.php
Lines:

1 to 81 of 81
  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;
  }
 

 View on GitHub View on Trac

Published: 25th November 2019 | Last updated: 21st August 2020

Primary Sidebar

Information

Function name: _WP_Editors::wp_link_query
Class ref: _WP_Editors
Plugin ref: WordPress
Version: 5.6
Sourcefile: wp-includes/class-wp-editor.php
File ref: wp-includes/class-wp-editor.php
API type: private
Deprecated?: No
API Letters: _,E,L,W

Footer

WP-a2z
WordPress core a2z
WordPress core only
WordPress 5.6
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  core.wp-a2z.org
© Copyright WP-a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites