Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a "report" Custom Post Type registered in this way:

register_post_type(
    'report',
    array(
        'label' => 'Reports',
        'description' => '',
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'rewrite' => array('slug' => ''),
        'query_var' => true,
        'exclude_from_search' => false,
        'supports' => array('custom-fields','comments','author',),
        ...
    )
);

As you can see, my report does not support title, but only custom-fields, comments, and author:

'supports' => array('custom-fields','comments','author',)

Hovewer, since the permalink of a post normally is something like:

http://mywebsitename.com/report/the-title

now I always get something like:

 http://mywebsitename.com/report/auto-draft/

I suppose that "auto-draft" is the title that is given by default to my report. I have no idea how to give a reasonable permalink. I would like to give one based on the custom-fields.

share|improve this question

1 Answer 1

up vote 1 down vote accepted
I have no idea how to give a reasonable permalink.

Give it a title. You don't have to use the title for anything but the permalink, and it will be used in the page title as well most likely but since it is already exposed in the permalink I don't see the harm. You never have to print it anywhere else if you don't want to. Not to be ornery, but that is the obvious solution and then everything more or less falls into place.

'title' is not something you can easily opt out of. How do you identify the reports on the "edit" screen for example? Those should probably all say "auto-draft" too, right? Or something pretty close? The page title-- on this page it looks like "plugin development - Give a permalink to ..."-- is usually set to the post title or derived from it. That bit shows up in most search engine results so you really need a decent title there if this is going to be exposed to the public. If you weren't looking to have the permalinks it would be different. You'd need to write your own interface to view the reports but at least some of the problems would not occur.

If you really want to, you could probably set the slug manually by hooking into the save_post filter and that might get a decent permalink. I don't think it will help with the admin screen though or with the page title. You should also be able use the slug the slug in the admin edit panel, but that is more code to write.

Please reconsider your decision not to use the title. That decision is costing you a fair bit of work, and I can't see the benefit.

share|improve this answer
    
Thank you. Very convincing. Just a question: in the admin page, can I rename "insert title here" in something other? I know it's a "title", but I would prefer if the other authors use a more fitting name. –  User Dec 12 '12 at 16:24
1  
I'd consider that a new question but there is a enter_title_here filter that looks to be designed to do just what you are asking. Look in wp-admin/edit-form-advanced.php. –  s_ha_dum Dec 12 '12 at 16:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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