Skip to content

Instantly share code, notes, and snippets.

@luisfdeandrade
Last active January 4, 2016 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luisfdeandrade/8577285 to your computer and use it in GitHub Desktop.
Save luisfdeandrade/8577285 to your computer and use it in GitHub Desktop.
Searching posts by multiple meta_key values.
// Change ids to int.
foreach ($clientes as $key => $value) {
$clientes[$key] = (int) $value;
}
$args = array(
'post_type' => 'clientes',
'post_status' => 'publish',
'meta_query' => array(
'relation' => 'OR'
)
);
foreach ($clientes as $key => $value) {
$args['meta_query'][] = array(
'key' => 'representante_clientes',
'value' => ":". $value. ";",
'compare' => 'LIKE'
);
}
$posts = get_posts($args);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment