Du musst dich anmelden um Beiträge und Themen zu erstellen. Einloggen · Registrieren

Display Private Posts to Logged-in Users

To display private posts to your logged-in users, you will need to add a custom field called “private” for each private post and give it a value of “true”. Then, replace your default WordPress loop with the following:

<?php if (have_posts()) : while (have_posts()) : the_post();

	$private = get_post_custom_values("private");
	if (isset($private[0]) && $private == "true") {
		if (is_user_logged_in()) {
			// Display private post to logged user
	} else {
		// Display public post to everyone

endwhile; endif; ?>

This custom loop will check each post for the presence of a custom-field value of true. For each post that has this value, the loop will then check to see if the user is logged into your site. If the user is in fact logged in, the loop will display the private post(s). Public posts will be displayed as usual and regardless of whether the user is logged in or not.

Source: Digging into WordPress