的参数之一register_post_type()
是publicly_queryable
. 只需将其设置为false,即可防止创建单个页面。您可能还希望从搜索中排除,等等。
https://codex.wordpress.org/Function_Reference/register_post_type
在WP Codex中给出的示例中,您可以看到此参数设置为
true
. 根据您的具体需要,您可以使用
public
参数或具有显式参数的可见性控制级别,如pas
publicly_queryable
.
https://codex.wordpress.org/Function_Reference/register_post_type#Example
Example code from WP Codex
add_action( \'init\', \'codex_book_init\' );
/**
* Register a book post type.
*
* @link http://codex.wordpress.org/Function_Reference/register_post_type
*/
function codex_book_init() {
$labels = array( /*removed for example*/ );
$args = array(
\'labels\' => $labels,
\'description\' => __( \'Description.\', \'your-plugin-textdomain\' ),
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'book\' ),
\'capability_type\' => \'post\',
\'has_archive\' => true,
\'hierarchical\' => false,
\'menu_position\' => null,
\'supports\' => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'excerpt\', \'comments\' )
);
register_post_type( \'book\', $args );
}
Post Type Archive这里需要注意的是,将public\\u queryable设置为false也会隐藏该帖子类型的归档页面。在上面的示例代码中
book
, 存档页位于
https://yourdomain.com/book 也将被删除。