【发布时间】:2017-02-16 02:45:36
【问题描述】:
我想创建一种非常具体的自定义帖子类型,它不应该允许用户搜索使用这种类型的帖子创建的其他帖子,而只允许他们查看发送给他们访问链接的帖子。我到目前为止是这样的:
function pp_register_post_type(){
$labels = array(
'name' => _x( 'Viajes', 'post type general name', 'negocios' ),
'singular_name' => _x( 'Viajes', 'post type singular name', 'negocios' ),
'menu_name' => _x( 'Viajes', 'admin menu', 'negocios' ),
'name_admin_bar' => _x( 'Viajes', 'add new on admin bar', 'negocios' ),
'add_new' => _x( 'Add New', 'Viajes', 'negocios' ),
'add_new_item' => __( 'Add New Viajes', 'negocios' ),
);
$args = array(
'labels' => $labels,
'description' => __( 'Description.', 'negocios' ),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'Viajes' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
'menu_icon' => 'dashicons-welcome-write-blog'
);
register_post_type('pp_portfolio', $args );
}
add_action('init', 'pp_register_post_type');
我认为将 'publicly_queryable' => true, 设置为 false 可以做到这一点,但它的作用是在创建帖子时不注册永久链接。然后,当我尝试查看帖子时,它只会将我发送到主页。
我应该如何设置$args 以避免archive.php 按日期或其他查询显示帖子列表?当有人试图搜索这些帖子类型时,我实际上想输出一个 404 页面。我该怎么办?
【问题讨论】:
标签: wordpress custom-post-type