wordpress - 为什么我的自定义帖子类型帖子不显示?

标签 wordpress themes custom-post-type posts

我创建了一个自定义帖子类型 - Press - 在functions.php中使用以下代码:

// Press Custom Post Type //

function press_custom_init() {

    $labels = array(
        'name' => _x('Press', 'post type general name'),
        'singular_name' => _x('Press', 'post type singular name'),
        'add_new' => _x('Add New', 'press'),
        'add_new_item' => __('Add New Press Item'),
        'edit_item' => __('Edit Item'),
        'new_item' => __('New Press Item'),
        'view_item' => __('View Press Item'),
        'search_items' => __('Search Press'),
        'not_found' =>  __('Nothing found'),
        'not_found_in_trash' => __('Nothing found in Trash'),
        'parent_item_colon' => ''
    );

    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'show_in_nav_menus' => false,
        'query_var' => true,
        'rewrite' => array('slug','pages'),
        'capability_type' => 'post',
        'hierarchical' => false,
        'menu_position' => 5,
        'supports' => array('title','editor','thumbnail','excerpt',)
      );

    register_post_type( 'press' , $args );
}
add_action( 'init', 'press_custom_init' );

我已经添加了该帖子类型的项目并在我的导航栏中添加了一个菜单项,但是当我点击链接时,我收到一条“未找到帖子”的消息。

您可以在这里查看:http://s13.mynewsitereview.com//press

请帮忙!

最佳答案

只需访问 WP-admin 中的永久链接页面 http://yoursite.com/wp-admin/options-permalink.php 即可解决此问题。

为什么?

在 WordPress 中创建任何插件(帖子类型、分类法等)后,WordPress 需要更新/创建一组新的重写规则(假设您使用的是漂亮的永久链接)。您需要做的就是访问后端的永久链接页面,以便为您的新帖子类型等生成新规则。技术术语是刷新重写规则 (http://codex.wordpress.org/Function_Reference/flush_rewrite_rules)

关于wordpress - 为什么我的自定义帖子类型帖子不显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11622819/

相关文章:

css - 防止 Wordpress 将逗号分隔的单词换行

php - 嵌套的 wordpress 术语列表 - 过滤器

sql - 为什么 WordPress 在其列名称前加上表名称前缀?

mysql - 带有自定义主题+ mysql的Docker-compose wordpress

html - CSS 菜单 - 自动向左或向右定位?

java - VAADIN 在生产模式下找不到主题

css - 在 Visual Studio Code 中设计垂直制表符缩进

wordpress - 帖子类型分层

php - 用于新发布的帖子的 WordPress Hook ,可以访问帖子元数据

wordpress - 使用 Relevanssi 查询进行木材分页