Skip to content

Commit

Permalink
feat: add name and email query logic
Browse files Browse the repository at this point in the history
  • Loading branch information
chickenn00dle committed Feb 15, 2024
1 parent c2c9821 commit ef70424
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions includes/hub/admin/class-woo.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ abstract class Woo {
* Runs the initialization.
*/
public static function init() {

$class_name = get_called_class();
$db_class_name = str_replace( 'Admin', 'Database', $class_name );
self::$post_types[] = $db_class_name::POST_TYPE_SLUG;
Expand Down Expand Up @@ -180,13 +179,30 @@ public static function pre_get_posts( $query ) {
public static function parse_query( $query ) {
global $pagenow;

if ( ! is_admin() || 'edit.php' !== $pagenow || ! $query->is_main_query() || ! in_array( $query->query_vars['post_type'], self::$post_types, true ) ) {
if ( ! is_admin() || 'edit.php' !== $pagenow || empty( $query->query_vars['s'] ) || ! in_array( $query->query_vars['post_type'], self::$post_types, true ) ) {
return;
}

error_log( 'Query: ' . $query->query_vars['s'] );
$search_term = $query->query_vars['s'];

// Query by name and/or email meta.
$meta_query = [
'relation' => 'OR',
[
'key' => 'user_name',
'value' => sanitize_text_field( $search_term ),
'compare' => 'LIKE',
],
[
'key' => 'user_email',
'value' => sanitize_text_field( $search_term ),
'compare' => 'LIKE',
]
];

$query->set( 'meta_query', $meta_query );

// Get Post IDs by query.
unset( $query->query_vars['s'] );
}


Expand Down

0 comments on commit ef70424

Please sign in to comment.