meta query – How making a new search box in admin post table working on a specific column
Presently I have already set a function that let me filter the ID column in the admin post table. It works with the exact “match”, if I write 8198 or 8175 i get the apartment (post) with exactly that code, if I write 81 nothing comes out. Now I’d like to add a new search box in the same page (see project in the pic: https://ibb.co/26Rpd7v ) filtering only the column “Nome” (name). All the names in that column are set in each edit post page using a custom field named “function_name”. The new search box shouldnt work with the “exact match”,If I write “Linda” I should get as results Linda 1 AND “Linda 2”. I write here the code I already have. How I can make a function registering a new search box and working on the above mentioned column and not with the exact match?
add_action( 'parse_request', 'cdxn_search_by_id' );
function cdxn_search_by_id( $wp ) {
global $pagenow;
if( !is_admin() && ‘edit.php’ != $pagenow && ‘post’ !== $_GET[‘post_type’]) {
return;
}
// If it's not a search return
if( !isset( $wp->query_vars['s'] ) ) {
return;
}
// Validate the numeric value
$id = absint( substr( $wp->query_vars['s'], 0 ) );
if( !$id ) {
return;
}
unset( $wp->query_vars['s'] );
$wp->query_vars['p'] = $id;
}
Leave an answer