Created
March 13, 2020 17:01
-
-
Save domosedov/75be0b4f6eaf800f7eeec9540f33309f to your computer and use it in GitHub Desktop.
Best method I’m aware of to search in array based fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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' | |
) | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source: https://barn2.co.uk/querying-posts-by-custom-field-acf/