Check if string exists in meta key string using meta_query check in wordpress get_posts function


Staff member
OK you would think this is a fairly trivial piece of code, but it is not working.

The code below is not broken, it is just not working as it should.


Ok, in wordpress I have a custom field in my custom post-type: <strong>individual</strong>, this custom field has a meta_key of: <strong>login_email</strong>

The contents of this meta_key is simply email addresses.

Here are some examples of the contents..


or even just a single email string..


OK, so now you seen the string contents of the custom field. I can explain what I am trying to achieve.

I have this variable...
$current_user_email = $current_user-&gt;user_login;

Which is a single email address string.

I then need to find if this email address exists within the meta_key contents. So this how I've done it...

$lastposts = get_posts(array(
    'posts_per_page'    =&gt; 1,
    'post_type'         =&gt; 'individual',
    'post_status'       =&gt; 'private',
    'meta_query'        =&gt; array(
            'key' =&gt; 'login_email',
            'value' =&gt; $current_user_email,
            'compare' =&gt; 'IN'


In my example above, if I echo
it outputs
But even though [email protected] exists in one of the custom fields like this... , my get_post returns nothing.

If I then go to the post editor and remove all the other emails from the custom field so is the only text in the custom field, then the above query works!

My question is, how can I get meta_query to find within a meta_key which contains this string:
Because '<strong>IN</strong>' is not doing what it is meant to.


Code taken from <a href="" rel="nofollow"></a>