We're working on a plugin where any logged-in user has the ability to submit a new "pitch", or standard post type with custom status of "pitch". Once the pitch is in the system, other logged-in users can vote on the idea, volunteer to participate, or comment on the story in progress.

It was simple to list all unpublished posts on a single view by querying the database for posts with post_status != 'publish'. I'd like to set it up so both logged-in and unlogged-in visitors can click through on the title and view the post on a single view as well. Default WordPress behavior is to return a 404 unless you have sufficient permissions. I believe viewing permissions are handled in the query object, and I don't see a simple way to unset them.

Any creative ideas? Thanks in advance.


Answered my own question on this one. As it turns out, it was pretty simple in WordPress 2.9.2. Basically, I applied a filter to 'the_posts' which would run another query if the object was empty. Because we're looking up posts that haven't been published, we need to use our own custom SQL as well. Trying to use the WP_Query object will, well, put you in an endless recursive loop.

  • That link from your answer doesn't work now. Can you help me with the same problem, how can I show unpublished post to unregistered user? – Dmytro Zarezenko Jul 18 '13 at 19:38

If you're using WP 3.0+ you should be able to use the register_post_status() method to register the new status as public. I don't see it in the codex yet, but below is what is documented:

 * Register a post type. Do not use before init.
 * A simple function for creating or modifying a post status based on the
 * parameters given. The function will accept an array (second optional
 * parameter), along with a string for the post status name.
 * Optional $args contents:
 * label - A descriptive name for the post status marked for translation. Defaults to $post_status.
 * public - Whether posts of this status should be shown in the admin UI. Defaults to true.
 * exclude_from_search - Whether to exclude posts with this post status from search results. Defaults to true.
 * @package WordPress
 * @subpackage Post
 * @since 3.0.0
 * @uses $wp_post_statuses Inserts new post status object into the list
 * @param string $post_status Name of the post status.
 * @param array|string $args See above description.
function register_post_status($post_status, $args = array()) {....

Based on this, you should just be able to call:

function add_pitch_status() {
    register_post_status('pitch', array('public'=>true));
add_action('init', 'add_pitch_status');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.