Skip to content

Instantly share code, notes, and snippets.

@domosedov
Created March 13, 2020 17:01
Show Gist options
  • Save domosedov/75be0b4f6eaf800f7eeec9540f33309f to your computer and use it in GitHub Desktop.
Save domosedov/75be0b4f6eaf800f7eeec9540f33309f to your computer and use it in GitHub Desktop.
Best method I’m aware of to search in array based fields
$search_value = 'xyz'; // whatever
$field_value = sprintf( '^%1$s$|s:%2$u:"%1$s";', $search_value, strlen( $search_value ) );
$args = array(
'post_type' => 'post',
'meta_query' => array(
array(
'key' => 'user_field',
'value' => $field_value,
'compare' => 'REGEXP'
)
)
);
@domosedov
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment