LLMS_Admin_Post_Table_Orders::modify_admin_search( WP_Query $query )
Modify the search query for various post types before retrieving posts.
Parameters Parameters
- $query
-
(WP_Query) (Required) Query object.
Return Return
(WP_Query)
Source Source
File: includes/admin/post-types/post-tables/class.llms.admin.post.table.orders.php
public function modify_admin_search( $query ) { // On the admin posts order table. // Allow searching of custom fields. if ( is_admin() && ! empty( $query->query_vars['s'] ) && isset( $query->query_vars['post_type'] ) && 'llms_order' === $query->query_vars['post_type'] ) { // What we are searching for. $term = $query->query_vars['s']; // Search wp_users. $user_query = new WP_User_Query( array( 'search' => '*' . esc_attr( $term ) . '*', 'search_columns' => array( 'user_login', 'user_url', 'user_email', 'user_nicename', 'display_name' ), 'fields' => 'ID', ) ); // Search wp_usermeta for First and Last names. $user_query2 = new WP_User_Query( array( 'fields' => 'ID', 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'first_name', 'value' => $term, 'compare' => 'LIKE', ), array( 'key' => 'last_name', 'value' => $term, 'compare' => 'LIKE', ), ), ) ); $results = wp_parse_id_list( array_merge( (array) $user_query->get_results(), (array) $user_query2->get_results() ) ); // Add metaquery for the user id. $meta_query = array( 'relation' => 'OR', array( 'key' => '_llms_user_id', 'value' => $results, 'compare' => 'IN', ), ); // We have to kill this value so that the query actually works. $query->query_vars['s'] = ''; // Set the query. $query->set( 'meta_query', $meta_query ); // Add a filter back in so we don't have 'Search results for ""' on the top of the screen. // @note we're not super proud of this incredible piece of duct tape. add_filter( 'get_search_query', function( $q ) { if ( '' === $q ) { return llms_filter_input_sanitize_string( INPUT_GET, 's' ); } } ); } return $query; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
5.9.0 | Stop using deprecated FILTER_SANITIZE_STRING . |
3.35.0 | Sanitize $_GET data. |
3.24.3 | Unknown |
2.5.0 | Introduced. |