Exclude Listings from Link Search

When you make a link in the WordPress editor, a link search tool pops up allowing you to search your content. By default it searches all public post types. On a project we had a lot of property listings which made link searching difficult. The code below excludes the ‘listing’ post type from that link search.

<?php
/**
* Exclude Listings from Link Search
*
* @author Bill Erickson
* @link http://www.billerickson.net/code/exclude-listings-from-link-search
*
* @param array $query, wp_query arguments
* @return array $query
*/
function be_exclude_listings_from_link_search( $query ) {
$query['post_type'] = array_diff( $query['post_type'], array( 'listing' ) );
return $query;
}
add_filter( 'wp_link_query_args', 'be_exclude_listings_from_link_search' );
view raw functions.php hosted with ❤ by GitHub

Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk