WordPress.org

Support

Support » How-To and Troubleshooting » post visible only when not logged

post visible only when not logged

  • How do I make a post ONLY visble to visitors who are NOT logged in? Basically, a welcome message that anyone logged in will not need to see.

    Thanks,
    jw

Viewing 4 replies - 1 through 4 (of 4 total)
  • Do you mean just a small or a whole post? In the first case, something like this should do it (inside of a template 😉 ) 🙂

    <?php if (!$user_ID): ?>
    <p>Hello guest :-)</p>
    <?php endif; ?>

    If zeroK’s suggestion doesn’t work, make sure to scope $user_ID to global first:

    <?php global $user_ID; if (!$user_ID): ?>
    <p>Hello guest :-)</p>
    <?php endif; ?>

    See my plugin for a way to call a specific post:

    http://guff.szub.net/2005/01/27/get-a-post/

    Okay, I’m getting warm…

    I installed the get-a-post plugin and I added this code just above the Loop:

    <?php global $user_ID; if (!$user_ID): ?>
    <p>Hello guest :-)</p>
    <?php get_a_post('post#'); ?>
    <h3><?php the_title(); ?></h3>
    <?php the_content(); ?>
    <?php endif; ?>

    When I’m logged in, it does nothing… that is good.

    When I log out, I see the ‘Hello Guest’ text, so I know it’s picking up that I’m not logged in, but…

    instead of the post I want to see it loads my contact form!?

    I tried different posts by number and by slug… with and without quotes… still nothing but the contact form.

    I have no idea why it would grab the Contact Form!?

    Definitely on the right track, but I must not be implementing the get-a-post properly.

    Thanks,
    jw

    aha!…

    I used this hack posted by “pati” at the get-a-post website:

    “…try putting parentheses around the last $query_suffix string, like this: $query_suffix = “(post_status = ‘publish’ OR post_status = ’static’)”;

    That fixed it!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘post visible only when not logged’ is closed to new replies.
Skip to toolbar