Skip to content
All gists
Back to GitHub
Sign in
Sign up
Sign in
Sign up
{{ message }}
Instantly share code, notes, and snippets.
birgire
/
menu-quick-search-tags-enhancements.php
Created
Jun 21, 2016
Star
0
Fork
0
Star
Code
Revisions
2
Embed
What would you like to do?
Embed
Embed this gist in your website.
Share
Copy sharable link for this gist.
Clone via HTTPS
Clone with Git or checkout with SVN using the repository’s web address.
Learn more about clone URLs
Download ZIP
WordPress Plugin: Search For Name Or Description In The Quick Search For Tags In The Menu Editor
Raw
menu-quick-search-tags-enhancements.php
This file contains 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
Show hidden characters
<?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
You can’t perform that action at this time.
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.