1

This might seem a little odd as a method.

I have posts on my wordpress website, which has a custom field called 'login_email'

In my theme files, I have this query...

$press = new WP_Query(array(
    'posts_per_page' => -1,
    'post_type'     => 'download',
    'post_status'   => 'private',
    'meta_query'    => array(
        array(
            'key' => 'login_email',
            'value' => $current_user->user_login,
            'compare' => '='
        )
    )      
));

This simply retrieves private posts which has the login_email custom field value which that matches $current_user->user_login

Currently in my login_email custom field i have this value...

[email protected]

No what I would like to be able to do is add more emails to this custom field seperate by a comma like this...

[email protected], [email protected], [email protected]

...and for my query above to be able to recognise one email out of this list.


For example if the user [email protected] is logged in, then because colins email exists in this custom field (along with josh & jimbo's email) then the post will be returned in the query.

I hope this makes some kind of sense. Let me know if I need to elaborate more.

It's like I need to modify the compare in the query - but these are the only options I can find...

compare (string) - Operator to test. Possible values are '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN', 'EXISTS' (only in WP >= 3.5), and 'NOT EXISTS' (also only in WP >= 3.5). Default value is '='. Source

...I've tested EXISTS but does not return any posts.


Has any one got a clever fix or idea?


Thanks Josh

1 Answer 1

0

Please try the operator IN. This will allow you to search in multiple emails.

Follow the IN clause written here: http://core.trac.wordpress.org/ticket/14997

Sign up to request clarification or add additional context in comments.

3 Comments

I tried this but no post are returned. And the current username is in the login_email string.
What is a clause? Do I need to install a function or is the operator IN meant to work?
Thats odd, IN doesnt seem to find the emails in the custom field. Hmm I wonder why that could be

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.