By default, if you do a search on the tickets list in the admin back end, it only searches the ticket content and title. If you want to be able to the search for tickets by the ID, add the following snippet to your functions. Then, to search by ticket ID, use a the number symbol and the ID, like #789.
/**
* Search the admin Tickets list by Ticket ID #
*/
add_action( 'parse_request', 'eddstix_search_by_id' ) );
public function eddstix_search_by_id( $wp ) {
global $pagenow;
// If it's not the tikcet list, return
if( ! is_admin() || 'edit.php' != $pagenow || ! isset( $wp->query_vars['post_type'] ) || 'edd_ticket' != $wp->query_vars['post_type'] ) {
return;
}
// If it's not a search, return
if( ! isset( $wp->query_vars['s'] ) ) {
return;
}
// If it's a search but there's no prefix, return
if( '#' != substr( $wp->query_vars['s'], 0, 1 ) ) {
return;
}
// Validate the numeric value
$id = absint( substr( $wp->query_vars['s'], 1 ) );
if ( ! $id ) {
return; // Return if no ID, absint returns 0 for invalid values
}
// If we reach here, all criteria is fulfilled, unset search and select by ID instead
unset( $wp->query_vars['s'] );
$wp->query_vars['p'] = $id;
// Replace the query string next to "Search results for "
add_filter( 'get_search_query', function( $s ) { return $_GET['s']; } );
}
Questions and Comments are Welcome