Skip to content

Instantly share code, notes, and snippets.

@birgire
Created June 21, 2016 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save birgire/b7001f51b3ad970f37fee2b8f854d939 to your computer and use it in GitHub Desktop.
Save birgire/b7001f51b3ad970f37fee2b8f854d939 to your computer and use it in GitHub Desktop.
WordPress Plugin: Search For Name Or Description In The Quick Search For Tags In The Menu Editor
<?php
/**
* Plugin Name: Quick Search Menu Enhancement
* Description: Search for name or description in the quick-search for tags in the menu editor
* Plugin URI: https://gist.github.com/birgire/b7001f51b3ad970f37fee2b8f854d939
* Author: birgire
* Version: 1.0.0
*/
/**
* Replace the name__like with the custom _name_or_description__like attribute of get_terms()
* during the post_tag search in the menu backend page.
*/
add_filter( 'get_terms_args', function( array $args, array $taxonomies )
{
if(
doing_action( 'wp_ajax_menu-quick-search' )
&& 'quick-search-taxonomy-post_tag' === filter_input( INPUT_POST, 'type' )
&& isset( $args['name__like'] )
) {
$args['_name_or_description__like'] = $args['name__like'];
unset( $args['name__like'] );
}
return $args;
}, 10, 2 );
/**
* Support the custom _name_or_description__like attribute of get_terms()
*/
add_filter( 'terms_clauses', function( $clauses, $taxonomies, $args ) use ( &$wpdb )
{
if(
! empty( $args['_name_or_description__like'] )
&& ! empty( $clauses['where'] )
) {
$like = '%' . $wpdb->esc_like( $args['_name_or_description__like'] ) . '%';
$clauses['where'] .= $wpdb->prepare(
" AND ( t.name LIKE %s OR tt.description LIKE %s ) ",
$like,
$like
);
}
return $clauses;
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment