Custom post type’s get_permalink returns wrong url

Currently my permalink setting is /paper/%postname%/.

I am developing a plugin, so the following is done during the activation.

Read More

I am programatically adding a new custom-post-type called ‘meta’, like this (at ‘init’):

register_post_type( POST_TYPE,
  array(
  'labels' => array('menu_name' => 'meta'),
  'public' => true,
  'rewrite' => array('with_front'=>false,'slug'=>'meta','pages'=>false)
  )
);

Then in the activation I programatically added a meta post, and use get_permalink(). But I get the following url:

http://localhost/wordpress/paper/faq/

This url leads to the ‘not found’ page. The correct url should be:

http://localhost/wordpress/meta/faq/

In the admin meta post edit page, the displayed permalink is the correct http://localhost/wordpress/meta/faq

I also tried to flush_rewrite_rules(); before I call get_permalink(). But it didn’t work.

Does anyone have any idea?

Related posts

Leave a Reply

1 comment

  1. At what stage are you registering your post type? If it’s going right in the admin I’m thinking that you might be registering your post type too late. It has to be done on init to work…

    Also, removing the 'pages'=>false might just fix it.