Home › Forums › Front-end Issues › Query posts by checkbox value NOT IN Array › Reply To: Query posts by checkbox value NOT IN Array
There is no solution just using ACF. If you want to store the value in the standard WP format then what you’ll need to do is create another custom field that is not part of ACF and when a values is saved to then update the value in the other field. For example:
// priority of 20 to run after acf has updated value
add_action('acf/save_post', 'convert_my_checkbox_to_standard', 20);
function convert_my_checkbox_to_standard($post_id) {
$values = get_field('my_check_box_field', $post_id);
delete_post_meta($post_id, 'my_converted_checkbox_field');
if (!count($value)) {
// no values, bail early
return;
}
foreach ($values as $value) {
add_post_meta($post_id, 'my_converted_checkbox_field', $value, false);
}
}
With this in place you can then do your searches based on the converted field rather than the ACF field.
If you’re interested I have created an entire plugin that’s designed for converting values in ACF fields to make them easier to use in queries https://github.com/Hube2/custom-field-converter
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.