Last active
December 22, 2015 13:08
-
-
Save DrewAPicture/6477198 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Filter the link query arguments. | |
* | |
* Allows modification of the link query arguments before querying. | |
* | |
* @since 3.7.0 | |
* | |
* @param array $query { | |
* An array of query arguments. | |
* | |
* @type string 'post_type' The post type. | |
* @type bool 'suppress_filters' Whether to suppress filters. | |
* @type bool 'update_post_term_cache' Whether to update the post term cache. | |
* @type bool 'update_post_meta_cache' Whether to update the post meta cache. | |
* @type string 'post_status' The post status. | |
* @type string 'order' How to order the query, ascending or descending. | |
* @type string 'orderby' What field to order the query by. | |
* @type int 'posts_per_page' The number of posts to query for. | |
* } | |
*/ | |
$query = apply_filters( 'wp_link_query_args', $query ); | |
// Do main query. | |
$get_posts = new WP_Query; | |
$posts = $get_posts->query( $query ); | |
// Check if any posts were found. | |
if ( ! $get_posts->post_count ) | |
return false; | |
// 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, | |
); | |
} | |
/** | |
* Filter the link query results. | |
* | |
* Allows modification of the returned link query results. | |
* | |
* @since 3.7.0 | |
* | |
* @param array $results { | |
* @type int 'ID' The post id. | |
* @type string 'title' The post title. | |
* @type string 'permalink' The 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 query arguments @see 'wp_link_query_args' filter. | |
* } | |
*/ | |
return apply_filters( 'wp_link_query', $results, $query ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment