0

I was wondering if it's possible to display certain content if a user meta field is set to a certain value.

The most related thing I could find is get user meta, however it seems to get the user meta from the author of the page/post, and not from the logged in user - correct?

Appreciate any hints - cheers!

2
0

No, not correct - get_user_meta() returns meta data based on the $user_id parameter you provide. You can combine it with get_current_user_id() to check if an user is logged in and than - if so - get the post meta. E.g. like this:

$curr_user_id = get_current_user_id();
// the value is 0 if the user isn't logged-in
if ( $curr_user_id != 0 ) {
    // we know now the user is logged-in, so we can use his/her ID to get the user meta
    $um_value = get_user_meta( $curr_user_id, 'your-key', true );
    // now we check if the value is correct
    if ( ! empty( $um_value ) && $um_value == 'your-value' ) {
        // if so we can output something
        echo 'user meta has the value';
    }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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