WordPress自定义帖子类型:按ID查询有效,按post_name不起作用 [英] WordPress custom post type: Query by id works, by post_name doesn't
问题描述
我需要有关Wordpress和自定义帖子类型/永久链接的帮助.
I would need some help with Wordpress and custom post types/permalinks.
我使用以下参数以名称"services"注册了自定义帖子类型:
I registered custom post type by the name "services" with the following arguments:
$args = array(
'labels' => $labels,
'singular_label' => __('services'),
'public' => true,
'query_var' => true,
'show_ui' => true,
'menu_icon' => get_stylesheet_directory_uri() . '/img/wp-menu-ico.png',
'menu_position' => null,
'capability_type' => 'page',
'hierarchical' => false,
'rewrite' => array('slug' => 'services', 'with_front' => TRUE),
'supports' => array('title', 'editor', 'thumbnail', 'page-attributes')
);
现在,我以"Make up"和"make-up"为标题创建新帖子.当我尝试使用预览"链接从WP仪表板预览此帖子时,它显示404.我也无法从仪表板外部查询此帖子.
Now I create new post by the title of "Make up" and slug "make-up". When I try to preview this post from WP dashboard using the Preview link it gives me 404. I can't query this post from outside the dashboard too.
现在,我发现当我使用以下url结构时,它向我显示了该帖子:
/?post_type=services&p=243
Now I found that when I use the following url structure it shows me the post:
/?post_type=services&p=243
但是这不起作用:/?services=make-up
我想做的是使用带有自定义帖子类型的漂亮url,这是行不通的.我禁用了WP选项中的漂亮永久链接,但仍然无法正常工作.
What I'm trying to do is to use pretty urls with custom post type, which doesn't work. I disabled the pretty permalinks in WP options and still doesn't work.
有什么主意我在做错什么吗?
Any ideas what am I doing wrong?
推荐答案
尝试转到Settings > permalinks
并按Save Changes
按钮.并再次预览您的自定义帖子
Try going to Settings > permalinks
and hit Save Changes
button. and preview your custom post again
这篇关于WordPress自定义帖子类型:按ID查询有效,按post_name不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!