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.
<hr/>
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..
or even just a single email string..
<hr/>
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...
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...
<br/>
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.
<br/>
Code taken from <a href="http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters" rel="nofollow">http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters</a>
<br/>
Thanks
The code below is not broken, it is just not working as it should.
<hr/>
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..
Code:
bob.dougal[email protected], [email protected], [email protected]
or..
or even just a single email string..
Code:
<hr/>
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...
Code:
$current_user_email = $current_user->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...
Code:
$lastposts = get_posts(array(
'posts_per_page' => 1,
'post_type' => 'individual',
'post_status' => 'private',
'meta_query' => array(
array(
'key' => 'login_email',
'value' => $current_user_email,
'compare' => 'IN'
)
)
));
<br/>
In my example above, if I echo
Code:
$current_user_email
Code:
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
Code:
My question is, how can I get meta_query to find
Code:
Because '<strong>IN</strong>' is not doing what it is meant to.
<br/>
Code taken from <a href="http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters" rel="nofollow">http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters</a>
<br/>
Thanks