无论我如何尝试,都无法查看自定义帖子类型

时间:2020-03-29 作者:Stefan S

这是我注册帖子类型的代码:

// Register new post type, User Conversations: b2bking_conversation
        add_action( \'init\', array($this, \'b2bking_register_post_type_conversation\'), 0 );
function b2bking_register_post_type_conversation() {
        // Build labels and arguments
        $labels = array(
            \'name\'                  => __( \'Conversations\', \'b2bking\' ),
            \'singular_name\'         => __( \'Conversation\', \'b2bking\' ),
            \'all_items\'             => __( \'Conversations\', \'b2bking\' ),
            \'menu_name\'             => _x( \'Conversations\', \'Admin menu name\', \'b2bking\' ),
            \'add_new\'               => __( \'Start Conversation\', \'b2bking\' ),
            \'add_new_item\'          => __( \'Start new conversation\', \'b2bking\' ),
            \'edit\'                  => __( \'Edit\', \'b2bking\' ),
            \'edit_item\'             => __( \'Edit conversation\', \'b2bking\' ),
            \'new_item\'              => __( \'New conversation\', \'b2bking\' ),
            \'view_item\'             => __( \'View conversation\', \'b2bking\' ),
            \'view_items\'            => __( \'View conversations\', \'b2bking\' ),
            \'search_items\'          => __( \'Search conversations\', \'b2bking\' ),
            \'not_found\'             => __( \'No conversations found\', \'b2bking\' ),
            \'not_found_in_trash\'    => __( \'No conversations found in trash\', \'b2bking\' ),
            \'parent\'                => __( \'Parent conversation\', \'b2bking\' ),
            \'featured_image\'        => __( \'Conversation image\', \'b2bking\' ),
            \'set_featured_image\'    => __( \'Set conversation image\', \'b2bking\' ),
            \'remove_featured_image\' => __( \'Remove conversation image\', \'b2bking\' ),
            \'use_featured_image\'    => __( \'Use as conversation image\', \'b2bking\' ),
            \'insert_into_item\'      => __( \'Insert into conversation\', \'b2bking\' ),
            \'uploaded_to_this_item\' => __( \'Uploaded to this conversation\', \'b2bking\' ),
            \'filter_items_list\'     => __( \'Filter conversations\', \'b2bking\' ),
            \'items_list_navigation\' => __( \'Conversations navigation\', \'b2bking\' ),
            \'items_list\'            => __( \'Conversations list\', \'b2bking\' )
        );
        $args = array(
            \'label\'                 => __( \'Conversation\', \'b2bking\' ),
            \'description\'           => __( \'This is where you can create new conversations\', \'b2bking\' ),
            \'labels\'                => $labels,
            \'supports\'              => array(\'title\',\'editor\',\'author\', \'comments\',\'thumbnail\'),
            \'hierarchical\'          => false,
            \'public\'                => true,
            \'publicly_queryable\'    => true,
            \'show_ui\'               => true,
            \'show_in_menu\'          => \'b2bking\',
            \'menu_position\'         => 100,
            \'show_in_admin_bar\'     => true,
            \'can_export\'            => true,
            \'has_archive\'           => true,
            \'exclude_from_search\'   =>  false,
            \'capability_type\'       => \'post\',
            \'rewrite\' =>            array("slug" => "conversations"),
        );


    // Actually register the post type
    register_post_type( \'b2bking_conversation\', $args );
    }
无论我做什么,我都无法查看这些帖子。该链接要么转到404或只能看到默认Hello World帖子的页面,要么重定向到首页。

我已经保存了永久链接,尝试了flush\\u rewrite\\u rules(),尝试了多个域。。。

1 个回复
SO网友:simongcc

我想它实际上是注册的。我确实复制并粘贴了您的代码,以便在我的5.3.2安装中进行尝试。

您可以尝试注释以下内容以进行尝试。

// \'show_in_menu\'          => \'b2bking\',
然后你会发现它在你的左侧菜单上,可能在底部。因为您将位置设置为100。show_in_menu menu 也就是说,它将出现在一个名为“b2bking”的特定子菜单下。但如果该菜单段塞不存在,则不会显示。但是,它是注册的。您还可以通过访问链接来测试它是否已注册。

例如“http://your-site/wp-admin/edit.php?post_type=b2bking_conversation“”

如果已注册,您可以看到帖子列表屏幕,并为此帖子类型添加新帖子。

补充说明:我还改变了一件事。因为我在函数中测试它。phpso I只需将add\\u操作更改为

add_action( \'init\', \'your_function\' );
这样,可以减少其他问题,如插件是否激活。或者函数是否被调用。