找到这篇整洁的小文章,试试看!
http://ryansechrest.com/2013/04/remove-post-type-slug-in-custom-post-type-url-and-move-subpages-to-website-root-in-wordpress/
这是一个指南/教程,所以如果你访问他的网站,你应该能够获得更多关于这里发生了什么的信息。
By the way, 在这里请求插件是违反规则的。
add_action(
\'pre_get_posts\',
\'custom_pre_get_posts\'
);
function custom_pre_get_posts($query) {
global $wpdb;
if(!$query->is_main_query()) {
return;
}
$post_name = $query->get(\'pagename\');
$post_type = $wpdb->get_var(
$wpdb->prepare(
\'SELECT post_type FROM \' . $wpdb->posts . \' WHERE post_name = %s LIMIT 1\',
$post_name
)
);
switch($post_type) {
case \'services\':
$query->set(\'services\', $post_name);
$query->set(\'post_type\', $post_type);
$query->is_single = true;
$query->is_page = false;
break;
}
return $query;
}