Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

i've saved and array of 'open days' as a serialised array in a meta value.

I was hoping i could then just search this field for the selected dates but i can't seem to create a match.

serialised = a:2:{i:0;s:10:"2011-09-16";i:1;s:10:"2011-09-17";} ; // two open dates

and was trying this and some variation without luck ;

$values_serialized = serialize(array('2011-09-16')); // need to serialise???

$args =  array ('meta_query' => array( 
    array( 'key'=>'v-openDays', 'value'=>$values_serialized,'compare'=>'IN' ) 
  )
)
// IN or LIKE?

will also be searching for multiple days but need to get one working first! Help appreciated, Dc

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

Don't serialize the search value, just use 'value' => '2011-09-16' 'compare' => 'LIKE'.

Otherwise you're essentially looking for;

a:1:{i:0;s:10:"2011-09-16"}

Which of course doesn't actually match anywhere in;

a:2:{i:0;s:10:"2011-09-16";i:1;s:10:"2011-09-17";}
share|improve this answer
1  
yeh - finally figured out that much and also IN had to be LIKE. Cheers! –  daniel Crabbe Jun 27 '11 at 17:03
    
@daniel nice one - updated answer for 'correctness' ;) –  TheDeadMedic Jun 27 '11 at 18:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.