我想我的设置很简单。事实上,我有点惊讶,在这里搜索了半个小时后,答案并没有突然出现。
以下是创建我的CPT的代码:
register_post_type(\'headline\', array(
\'labels\' => array(
\'name\' => \'Headlines\',
\'singular_name\' => \'Headline\',
\'add_new\' => \'Add Headline\',
\'add_new_item\' => \'Add Headline\',
\'edit_item\' => \'Edit Headline\',
\'new_item\' => \'New Headline\',
\'all_items\' => \'All Headlines\',
\'view_item\' => \'View Headline\',
\'search_items\' => \'Search Headlines\',
\'not_found\' => \'No matching headlines found\',
\'not_found_in_trash\' => \'No matching headlines found in Trash\',
\'parent_item_colon\' => \'\',
\'menu_name\' => \'Headlines\'
),
\'description\' => \'Headlines from around the world.\',
\'public\' => true,
\'supports\' => array(\'title\', \'editor\', \'author\', \'excerpt\', \'thumbnail\', \'trackbacks\', \'comments\', \'revisions\'),
\'taxonomies\' => array(\'category\', \'post_tag\'),
\'register_meta_box_cb\' => \'DfePostTypesHeadline::add_meta_boxes\',
\'has_archive\' => true,
\'rewrite\' => array(
\'with_front\' => false
),
\'can_export\' => true
));
问题是“with\\u front”调用。或者更确切地说,是重写规则本身。我有我的
flush_rewrite_rules()
插件激活/停用时发生调用。我可以看到。htaccess文件正在被重写,所以它正常工作。但WordPress仍然无法识别我的新permalink结构。
我不确定这是否相关,但我的register\\u post\\u类型调用正在“init”挂钩上进行。我想知道是否需要另一个钩子?
/* Giddyup */
public function DFEPostTypes() {
add_action( \'init\', \'DFEPostTypes::register_content_types\' );
add_action( \'admin_menu\', \'DFEPostTypes::admin_pages\' );
add_action( \'admin_enqueue_scripts\', \'DFEPostTypes::admin_scripts\' );
add_filter( \'template_include\', \'DFEPostTypes::template\' );
// Flush rewrite rules:
register_activation_hook( __FILE__, \'DFEPostTypes::flush_rewrite\' );
register_deactivation_hook( __FILE__, \'DFEPostTypes::flush_rewrite\' );
}
register_content_types()
是处理动态调用和注册我使用的内容类型的函数。