Support

Account

Home Forums General Issues Meta query array over serialized values

Solving

Meta query array over serialized values

  • Hi there,

    I’m trying to run a meta_query over a multi select serialized array. The following will work as a single value.

    'meta_query' => array(
    				  array(
    				      'key' => 'linked_outcomes',
    				      'value' => '"OUT-001-2"',
    				      'compare' => 'LIKE'
    				    )
    				  )

    However I would like it as an array of values i.e.

    'meta_query' => array(
    				  array(
    				      'key' => 'linked_outcomes',
    				      'value' => array('"$myserialized_values"'),
    				      'compare' => 'LIKE'
    				    )
    				  )

    Any ideas on how to do this?

    Thanks,
    Dan

  • Each value needs to be a separate meta query

    
    'meta_query' => array(
      'relation' => 'OR',
      array(
        'key' => 'linked_outcomes',
        'value' => '"value 1"',
        'compare' => 'LIKE'
      ),
      array(
        'key' => 'linked_outcomes',
        'value' => '"value 2"',
        'compare' => 'LIKE'
      )
    )
    
  • Yeah that’s what I thought, unfortunately that’s not going to work as there are a lot of values.

    Thanks for your input.
    Dan

  • What I would do is create an acf/save_post filter and I’d convert the values to a standard WP custom field and use the new field for searching. Downside of this is that if the site already has a lot of posts that all of them will need to be updated to add the new field.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.