开发者

WordPress custom post type: Query by id works, by post_name doesn't

开发者 https://www.devze.com 2023-01-15 12:13 出处:网络
I would need some help with Wordpress and custom post types/permalinks. I registered custom post type by 开发者_运维知识库the name \"services\" with the following arguments:

I would need some help with Wordpress and custom post types/permalinks.

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')
);

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.

Now I found that when I use the following url structure it shows me the post: /?post_type=services&p=243

This however doesn't work: /?services=make-up

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?


Try going to Settings > permalinks and hit Save Changes button. and preview your custom post again

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号