I'm using ACF Pro to get all my choices
or specific field. I want to store these choice values into an array structure like this...
$mstars = array(
'relation' => 'OR',
array (
'key' => 'product_owner',
'value' => 'Bob Ross',
'compare' => 'LIKE'
),
array(
'key' => 'product_owner',
'value' => 'Michael Jackson',
'compare' => 'LIKE'
),
array(
'key' => 'product_owner',
'value' => 'Tom Hanks',
'compare' => 'LIKE'
)
...Bob, Micheal and Tom are the only things coming from my select choices. The 'key' and 'compare' can be manully placed in my loop sense that never changes. How should I go about building that? This is what I have so far...
//I'm getting the ACF key to find my specific field
$field_key = "field_5b5b34f4ed085";
//I now have field data
$field = get_field_object($field_key);
//initiate an array
$mstars = [];
//loop through all my choices of this specific field
foreach($field['choices'] as $mkey => $mvalue) {
//how do I add 'key' => 'product_owner', to each sub array?
//how can I add Bob, Michael and Tom as values to each sub array?
//how do I add compare => 'LIKE' to each sub array?
}
//I could then use $mstars[] where needed for get_posts() arguments
Many thanks on how to do this!
A var_dump
of my choices looks like this...
var_dump($field['choices']);
array(6) {
["Michael Jackson"]=> string(16) "Michael Jackson"
["Bob Ross"]=> string(12) "Bob Ross"
["Tom Hanks"]=> string(13) "Tom Hanks"
}