Home › Forums › Backend Issues (wp-admin) › Field / SubField Searching within Admin Panel
I have a custom “course code” that I need my administrators to be able to type into the search bar and instantly find. I have these stored as field “course_number” and within a repeater “instance” with “instance_id”
These codes are showing on my custom column, http://i.imgur.com/kyhtibF.jpg
but not when searched directly http://i.imgur.com/lhcn55P.jpg
How do I add a filter that can tell WordPress to search on these custom fields?
i cant say how you add this with a filter.
but i can offer a workaround if you dont use core content-WP-wysiwyg (anyway or are able to dont use it.)
if you meet this requirement than look at my post inside this thread
with that “workaround” you should be able to find everything that you save like that with core-search, because you use searchable core as hidden placeholder. 😉
This certainly can work but I’d like to keep the content area as-is for excerpt functionality. I did find a solution but it looks like it searches all post_meta, so it’s not something that can specifically be set.
I would like to see a “Searchable” Boolean added to field types.
// Search on custom fields
function custom_search_join ($join){
global $pagenow, $wpdb;
$types = ['course'];
// I want the filter only when performing a search on edit page of Custom Post Type in $types array
if ( is_admin() && $pagenow=='edit.php' && in_array( $_GET['post_type'], $types ) && isset( $_GET['s'] ) ) {
$join .='LEFT JOIN '.$wpdb->postmeta. ' ON '. $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
}
return $join;
}
add_filter('posts_join', 'custom_search_join' );
function custom_search_where( $where ){
global $pagenow, $wpdb;
$types = ['course'];
// I want the filter only when performing a search on edit page of Custom Post Type in $types array
if ( is_admin() && $pagenow=='edit.php' && in_array( $_GET['post_type'], $types ) && isset( $_GET['s'] ) ) {
$where = preg_replace(
"/\(\s*".$wpdb->posts.".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
"(".$wpdb->posts.".post_title LIKE $1) OR (".$wpdb->postmeta.".meta_value LIKE $1)", $where );
}
return $where;
}
add_filter( 'posts_where', 'custom_search_where' );
function custom_search_distinct( $where ){
global $pagenow, $wpdb;
$types = ['course'];
if ( is_admin() && $pagenow=='edit.php' && in_array( $_GET['post_type'], $types ) && isset( $_GET['s'] ) ) {
return "DISTINCT";
}
return $where;
}
add_filter( 'posts_distinct', 'custom_search_distinct' );
The topic ‘Field / SubField Searching within Admin Panel’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.