自定义帖子类型导致找不到页面

时间:2014-10-31 作者:Aidan Knight

我在网上找到了一个基础教程,它详细介绍了如何从头开始创建插件,并设置了一个新的自定义帖子类型。我找不到任何基本的优惠券插件来完成我想要的,为什么我决定自己去创建一个。

不幸的是,在完成教程后,我来到了实际查看页面的部分,尽管发布了我的帖子,但却收到了一个“找不到页面”的提示。有谁能检查一下,让我确切地知道我做错了什么?

<?php

/**
* Plugin Name: Coupons
* Plugin URI: http://coupon.net
* Description: A coupon system plugin
* Version: 1.0.0
* Author: Brett Powell
* Author URI: http://coupon.net
**/

// Register the Custom Post Type "Coupon"
function register_cpt_coupon()
{
    $labels = array(
        \'name\' => _x( \'Coupons\', \'coupon\' ),
        \'singular_name\' => _x( \'Coupon\', \'coupon\' ),
        \'add_new\' => _x( \'Add New\', \'coupon\' ),
        \'add_new_item\' => _x( \'Add New Coupon\', \'coupon\' ),
        \'edit_item\' => _x( \'Edit Coupon\', \'coupon\' ),
        \'new_item\' => _x( \'New Coupon\', \'coupon\' ),
        \'view_item\' => _x( \'View Coupon\', \'coupon\' ),
        \'search_items\' => _x( \'Search Coupons\', \'coupon\' ),
        \'not_found\' => _x( \'No coupons found\', \'coupon\' ),
        \'not_found_in_trash\' => _x( \'No coupons found in Trash\', \'coupon\' ),
        \'parent_item_colon\' => _x( \'Parent Coupon:\', \'coupon\' ),
        \'menu_name\' => _x( \'Coupons\', \'coupon\' ),
    );

    $args = array(
        \'labels\' => $labels,
        \'hierarchical\' => true,
        \'description\' => \'Coupons filterable by company\',
        \'supports\' => array( \'title\', \'editor\', \'thumbnail\', \'revisions\', \'page-attributes\' ),
        \'taxonomies\' => array( \'genres\' ),
        \'public\' => true,
        \'show_ui\' => true,
        \'show_in_menu\' => true,
        \'menu_position\' => 5,
        \'menu_icon\' => \'dashicons-format-audio\',
        \'show_in_nav_menus\' => true,
        \'publicly_queryable\' => true,
        \'exclude_from_search\' => false,
        \'has_archive\' => true,
        \'query_var\' => true,
        \'can_export\' => true,
        \'rewrite\' => true,
        \'capability_type\' => \'post\'
    );

    register_post_type( \'coupon\', $args );
}

add_action( \'init\', \'register_cpt_coupon\' );

// Create Genre Taxonomy type
function genres_taxonomy()
{
    register_taxonomy(
        \'genres\',
        \'coupon\',
        array(
            \'hierarchical\' => true,
            \'label\' => \'Genres\',
            \'query_var\' => true,
            \'rewrite\' => array(
                \'slug\' => \'genre\',
                \'with_front\' => false
            )
        )
    );
}
add_action( \'init\', \'genres_taxonomy\');

// Function used to automatically create Coupon page.
function create_coupon_pages()
{
   //post status and options
    $post = array(
          \'comment_status\' => \'open\',
          \'ping_status\' =>  \'closed\' ,
          \'post_date\' => date(\'Y-m-d H:i:s\'),
          \'post_name\' => \'coupon\',
          \'post_status\' => \'publish\' ,
          \'post_title\' => \'Coupons\',
          \'post_type\' => \'page\',
    );
    //insert page and save the id
    $newvalue = wp_insert_post( $post, false );

    //save the id in the database
    update_option( \'couponpage\', $newvalue );
}

// // Activates function if plugin is activated
register_activation_hook( __FILE__, \'create_coupon_pages\');

?>

1 个回复
最合适的回答,由SO网友:jdm2112 整理而成

您很可能只需访问permalink设置页面即可刷新。转到“管理”>“设置”>“永久链接”。然后再次在前端尝试您的URL。

结束

相关推荐

Cache Get_posts

我有一个查询(见下文),它提供了一个由10个新闻项组成的列表,这些新闻项按元值“event\\u date”排序,并经过筛选,以便只显示比今天更早的帖子。处理此查询需要两秒钟,因此我正在寻找一种简单的方法来缓存结果,以加快加载时间。我已经使用了WPEngine,所以我不需要任何缓存插件。提前感谢您的帮助。<?php $today = time();?> <?php $args = array( \'numberposts\' => 10, \'orderb