Skip to content

Instantly share code, notes, and snippets.

@mujahidi
Created May 6, 2020 17:09
Show Gist options
  • Save mujahidi/ea94ad8b309f5f8c828d949c0df37c72 to your computer and use it in GitHub Desktop.
Save mujahidi/ea94ad8b309f5f8c828d949c0df37c72 to your computer and use it in GitHub Desktop.
Querying posts by ACF User field type
<?php
$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