0

I'm working with a child theme. Main theme has a custom post type called "Place". I need to change that into "Location". However, I changed all levels using wp_post_types object.

Now I need to change endpoint. In frontend, URLs are look like domain.com/place/a-permalink. I need to change that into domain.com/location/a-permalink

But I cannot change slug.

I checked some questions like this one. But cannot understand how to use with custom post type. I badly need your advice.

EDIT: In Parent theme, post type was registered this way:

register_post_type( "$custom_post_type", 
                array(  'label'             => CUSTOM_MENU_TITLE,
                        'labels'            => array(   'name'                  =>  CUSTOM_MENU_NAME,
                                                        'singular_name'         =>  CUSTOM_MENU_SIGULAR_NAME,
                                                        'add_new'               =>  CUSTOM_MENU_ADD_NEW,
                                                        'add_new_item'          =>  CUSTOM_MENU_ADD_NEW_ITEM,
                                                        'edit'                  =>  CUSTOM_MENU_EDIT,
                                                        'edit_item'             =>  CUSTOM_MENU_EDIT_ITEM,
                                                        'new_item'              =>  CUSTOM_MENU_NEW,
                                                        'view_item'             =>  CUSTOM_MENU_VIEW,
                                                        'search_items'          =>  CUSTOM_MENU_SEARCH,
                                                        'not_found'             =>  CUSTOM_MENU_NOT_FOUND,
                                                        'not_found_in_trash'    =>  CUSTOM_MENU_NOT_FOUND_TRASH ),
                        'public'            => true,
                        'can_export'        => true,
                        'show_ui'           => true, // UI in admin panel
                        '_builtin'          => false, // It's a custom post type, not built in
                        '_edit_link'        => 'post.php?post=%d',
                        'capability_type'   => 'post',
                        'menu_icon'         => get_bloginfo('template_url').'/images/favicon.ico',
                        'hierarchical'      => false,
                        'rewrite'           => array("slug" => "$custom_post_type"), // Permalinks
                        'query_var'         => "$custom_post_type", // This goes to the WP_Query schema
                        'supports'          => array(   'title',
                                                        'author', 
                                                        'excerpt',
                                                        'thumbnail',
                                                        'comments',
                                                        'editor', 
                                                        'trackbacks',
                                                        'custom-fields',
                                                        'revisions') ,
                        'show_in_nav_menus' => true ,
                        'taxonomies'        => array("$custom_cat_type","$custom_tag_type")
                    )
                );

AND AGAIN, I CANNOT TOUCH PARENT THEME, I HAVE TO DO EVERYTHING FROM CHILD THEME.

3
  • Can you show how you're using register_post_type() Commented Sep 23, 2014 at 7:33
  • I think you are doing things in a bad way. You should register your own post type with your name, labels and rewrite rules. Change/override all of that from a existing post type has no sense for me and you may find things that can not been overrided. And for your information: the post type slug (in your case "location") is a totally different thing of endpoint.
    – cybmeta
    Commented Sep 23, 2014 at 7:52
  • Well, this is client's requirements and I've to find an way to do that.
    – IFightCode
    Commented Sep 23, 2014 at 7:55

1 Answer 1

1

When you register your custom post type, you should use rewrite like this:

add_action('init', 'create_location');
function create_location() {
  register_post_type('location',
    array(
      'labels' => array(
        'name' => __('Locations'),
        'singular_name' => __('Location')
      ),
      'public' => true,
      'rewrite' => array(
        'slug' => 'location'
      )
    )
  );
}  

Don't forget to update your permalinks by going to example.com/wp-admin/options-permalink.php and click on Save Changes.

You should also be able to modify an already registered post type by using register_post_type() once again from the child theme.

From the description for register_post_type():

Create or modify a post type. register_post_type should only be invoked through the 'init' action. It will not work if called before 'init', and aspects of the newly created or modified post type will work incorrectly if called later.

References

Post Types

Modifying post type - using the registered_post_type hook

Function Reference/register post type

3
  • You probably missed my point, I've to work in child theme. Parent theme has already custom post type registered.
    – IFightCode
    Commented Sep 23, 2014 at 7:52
  • aha, I will update my answer then. Commented Sep 23, 2014 at 7:55
  • 1
    @Enthusiast - Here is another link talking about the same thing wordpress.stackexchange.com/questions/65075/… Commented Sep 23, 2014 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.