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])) {
      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:

     '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?