質問
ログインしたユーザーが新しい「ピッチ」を送信できるプラグイン、または「ピッチ」のカスタムステータスを持つ標準の投稿タイプを送信できるプラグインに取り組んでいます。ピッチがシステムに入ったら、他のログインユーザーはアイデアに投票したり、ボランティアに参加したり、進行中のストーリーにコメントしたりできます。
投稿のデータベースをクエリすることにより、1つのビューにすべての未発表の投稿をリストするのは簡単でした post_status != 'publish'
. 。ログインしていない訪問者の両方がタイトルをクリックして、単一のビューで投稿を表示できるように、セットアップしたいと思います。デフォルトのWordPressの動作は、十分な権限がない限り、404を返すことです。私は信じている 表示権限の表示は、クエリオブジェクトで処理されます, 、そして、私はそれらを解明する簡単な方法を見ていません。
創造的なアイデアはありますか?前もって感謝します。
解決
これに関する私自身の質問に答えました。結局のところ、WordPress 2.9.2では非常に簡単でした。基本的に、i フィルターを「the_posts」に適用しました オブジェクトが空の場合、別のクエリを実行します。公開されていない投稿を検索しているため、独自のカスタムSQLも使用する必要があります。 wp_queryオブジェクトを使用しようとすると、まあ、あなたを無限の再帰ループに入れます。
他のヒント
WP 3.0+を使用している場合は、register_Post_Status()メソッドを使用して、新しいステータスをパブリックとして登録できるはずです。私はまだコーデックスでそれを見ていませんが、以下は文書化されています:
/**
* 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()) {....
これに基づいて、あなたはただ電話できるはずです:
function add_pitch_status() {
register_post_status('pitch', array('public'=>true));
}
add_action('init', 'add_pitch_status');