Private Unpublished Content

Last modified: October 6, 2006 - 02:44

PLEASE NOTE These snippets are user submitted. Use at your own risk. For users who have setup drupal using an alternate database to the default (MYSQL), please note that the snippets may contain some database queries specific to MYSQL.

The following snippet lists the headlines of all the unpublished posts of the currently logged in user. The snippet is tested with Drupal 4.6.3.

<?php
global $user;
$listlength='20';
$curUserId=$user->uid;
$res = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.status = 0 AND n.uid='$curUserId'  ORDER BY n.created DESC"), 0, $listlength);
if (!
db_num_rows($res)) {
 
$output = t("You don't have unpublished content.");
} else {
 
$output = node_title_list($res);
}
print
$output;
?>

And this is what you need to copy and modify if you want to filter and list unpublished content only under specific content types.

<?php
global $user;
$listlength='20';
$nodetypes="('blog', 'story')"; // <-- define you content types here
$curUserId=$user->uid;
$res = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE *n.type IN $nodetypes AND n.status = 0 AND n.uid='$curUserId'  ORDER BY n.created DESC"), 0, $listlength);
if (!
db_num_rows($res)) {
 
$output = t("You don't have unpublished content.");
} else {
 
$output = node_title_list($res);
}
print
$output;
?>

Good luck!

 
 

Drupal is a registered trademark of Dries Buytaert.