Support » Fixing WordPress » Double conditions in "if" statement pls help

  • I’ve been working on this for 8 hours and it still doesn’t work.

    I want to hide part of the post of a specific category but only for users who are not logged in. I’ve tried everything on this forum and on others and I had no choice but to register here and post this. I’ got something so I’m half way of what I want but I don’t know how to do it.

    This what I want:

    If the unregistered user accesses a post from the Original category, then show a warning message telling him he must register to see that part.

    The same part of the post of the rest categories should be shown to unregistered users.

    Something like this

    if (unregistered and category is Original) then show warning message
    else show the post

    The problem is I don’t know how to use 2 conditionals.
    This is what I have so far.

    <?php if (is_user_logged_in() && in_category(‘original’)) : ?>

    //part to hide//

    <?php else :?>
    //warning message and registration link//
    <?php endif;?>

    The problem with this is that it does the exact opposite. It shows the message on all posts from all categories when logged out when it should only show it for posts that are in the Original category.

    When I’m logged in it shows the message to all posts except to the ones in the Original category when in reality it should not show the message at all.

    Can anybody tweak this code and make it right. Thank you so much. Any tip is highly appreciated

Viewing 4 replies - 1 through 4 (of 4 total)
  • if (unregistered and category is Original) then show warning message
    else show the post

    you already have it up there, so why did you code something different?

    <?php if ( !is_user_logged_in() && in_category( 'original' ) ): ?>
    //warning message and registration link
    <?php else : ?>
    //show post
    <?php endif; ?>

    Ahhhhh, thank you so much. It works perfectly. I knew I was close. The only thing i was missing was that exclamation mark ! in front of the first condition. What exactly does it do?

    Here you can see how it works, just click on any wallpaper tagged as original and you’ll see.

    the exclamation mark is for negation. it flips a true value to false, and vice versa.

    you can read it as ‘not’.

    ahh, I see. I didn’t know how to do that and I tried with:


    and also with:


    now I see why it didn’t work.

    Thanx again for your help. Hope it’s useful for someone else out there.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Double conditions in "if" statement pls help’ is closed to new replies.