题
我们正在处理一个插件,任何登录名用户都能提交具有“ pitch”的自定义状态的新“音调”或标准帖子类型。音调进入系统后,其他登录的用户可以对此想法进行投票,自愿参加或评论正在进行的故事。
通过查询数据库中的数据库中的帖子 post_status != 'publish'
. 。我想设置它,以便登录和未加入的访问者可以单击标题,并在单个视图上查看帖子。默认的WordPress行为是返回404,除非您有足够的权限。我相信 查看权限在查询对象中处理, ,而且我看不到一种简单的方法来解开它们。
有创意吗?提前致谢。
解决方案
回答了我自己的问题。事实证明,在WordPress 2.9.2中非常简单。基本上,我 将过滤器应用于“ 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');