【问题标题】:Make Custom Post Type in Wordpress Not Searchable使 Wordpress 中的自定义帖子类型不可搜索
【发布时间】: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


    【解决方案1】:

    【讨论】:

    • 非常感谢!我不知道我是怎么错过的。
    猜你喜欢
    • 1970-01-01
    • 2014-05-20
    • 2021-12-23
    • 1970-01-01
    • 2013-12-22
    • 2012-09-14
    • 2014-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多