Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
Because I can't post more than one link, here's how we're handling querying posts on the 'multi-pitch' view: github.com/studio20nyu/Assignment-Desk/blob/master/php/… –  Daniel Bachhuber Aug 29 '10 at 21:17
add comment

2 Answers 2

up vote 0 down vote accepted

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.

share|improve this answer
    
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
add comment

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');
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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