使用自定义帖子类型时,我陷入了一个两难境地,必须使用flush\\u rewrite\\u rules();当使用permalink结构时,否则将转到404。使用它后,它可以在一个CPT上工作,但如果你有2个或3个,我仍然有同样的问题,必须回到基本的永久链接设置。如果你能帮助我,那就太好了。
add_action(\'init\', \'video_register\');
function video_register() {
$labels = array(
\'name\' => _x(\'Video\', \'post type general name\'),
\'singular_name\' => _x(\'Video\', \'post type singular name\'),
\'add_new\' => _x(\'Add New\', \'Video\'),
\'add_new_item\' => __(\'Add New Video\'),
\'edit_item\' => __(\'Edit Video\'),
\'new_item\' => __(\'New Video\'),
\'view_item\' => __(\'View Video\'),
\'search_items\' => __(\'Search Video\'),
\'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,
\'query_var\' => true,
\'menu_icon\' => null,
\'rewrite\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'menu_position\' => null,
\'taxonomies\' => array(\'post_tag\'),
\'supports\' => array(\'title\',\'editor\',\'thumbnail\',\'custom-fields\', \'comments\',)
);
register_post_type( \'video\' , $args );
flush_rewrite_rules();
}
这是我为自定义帖子类型添加的内容。非常感谢。