Home › Forums › Backend Issues (wp-admin) › WP Query – Multiple values in ACF Checkbox › Reply To: WP Query – Multiple values in ACF Checkbox
Yes this does really seem like best practice, so I hope you’ll forgive me being dogged about understanding.
My understanding is clearly still flawed. from your article and your code above, I arrived at the following:
add_filter('acf/save_post', 'convert_event_status_to_standard_wp_meta', 20);
function convert_event_status_to_standard_wp_meta($post_id) {
$meta_key = 'status_wp';
delete_post_meta($post_id, $meta_key);
$saved_values = array();
$values = get_field('status', $post_id);
foreach ($values as $value) {
if (isset($saved_values[$value])) {
continue;
}
add_post_meta($post_id, $meta_key, $value, false);
$saved_values[$value] = $value;
}
}
I placed this in functions.php
(was that right?), and changed the query to include:
array(
'meta_key' => 'status_wp',
'value' => array('Cancelled', 'Exclude Past'),
'compare' => '!='
)
This gave me the following error:
Warning: trim() expects parameter 1 to be string, array given in [url]/wp-includes/class-wp-meta-query.php on line 695
Obviously I’ve not implemented this correctly. I’m guessing either my query is wrong, or I’ve not adapted the repeater example from your article correctly in the foreach
section of the code?
Thanks.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.