Home / login / Private posts for logged in users
  • How to Private posts for logged in users

    no thumbnail sorry: Private posts for logged in users

    Using this as your wordpress loop will display posts with the custom field of private only to users that are logged into your website.

    ( click code to copy )

    wordpress snippet : PHP

    <>
          if ( have_posts() ) :
          while ( have_posts() ) : the_post();
          // the loop
          $private = get_post_custom_values('private'); // read custom field
          if ( isset($private[0]) && $private == 'true' ) {
               if ( is_user_logged_in() ) {
                // display private post, only logged users
               }
          } else {
        // display public post, for every visitors
        }
        endwhile;
        endif;
    

    ( WordPress codex functions, hooks, in this snippet. )

    get_post, have_posts, the_post, get_post_custom, get_post_custom_values, is_user_logged_in,