Tagged: piklist_empty_post_title
- This topic has 7 replies, 2 voices, and was last updated 6 years, 8 months ago by
Steve.
-
AuthorPosts
-
-
May 29, 2015 at 4:03 pm #3759
gospelnerdMemberHow can I programatically set or change the permalink of a CPT that doesn’t support ‘title’? I don’t care to have the users mess with it. Right now it saves all the entries with the title ‘Auto Draft’ and the slug ‘auto-draft-{n}’
-
May 29, 2015 at 4:48 pm #3760
SteveKeymasterPiklist has a filter,
piklist_empty_post_title, that may help you. Check out this support ticket >Let us know if that helps.
-
May 29, 2015 at 5:02 pm #3761
gospelnerdMemberWell, that’s cool. I set the title to [user_login]-[time()] … but, the permalink is still auto-draft-{n} .. any way to hook it before the permalink gets created?
-
May 29, 2015 at 10:18 pm #3763
SteveKeymasterThis should work. Place it in your main plugin file or your themes
functions.phpfile:add_filter('piklist_empty_post_title', 'my_empty_post_title', 10, 2); function my_empty_post_title($data, $post_array) { global $current_user; get_currentuserinfo(); return $post_array['post_type'] == 'YOUR-POST-TYPE' ? $current_user->user_login . '-' . time() : $post_array['post_title']; } -
June 1, 2015 at 12:12 pm #3788
gospelnerdMemberThat’s basically what I have, Steve.
function set_cm_post_title($data, $post_array) { if ($post_array['post_type'] == 'cm-post') { //set the title to [user_login]_[time()] global $current_user; get_currentuserinfo(); $post_name = $current_user->user_login . '-' . time(); return $post_name; } else { return $post_array['post_title']; } } add_filter('piklist_empty_post_title', 'set_cm_post_title', 10, 2);This changes the title, but, the slug in the permalink is still ‘auto-draft-{n}’
-
June 1, 2015 at 12:23 pm #3789
SteveKeymaster@gospelnerd– It’s working fine for me… permalink is user_login-time.
-Make sure all other custom code is disabled.
-Disable ‘title’ in your supports parameter when registering post type.
-Save your permalink structure again… just to flush them.Let me know if that helps.
-
June 1, 2015 at 1:40 pm #3791
gospelnerdMemberAww.. sweet! It was the permalink flush I needed. Apparently just pressing ‘save’ on the Permalinks settings page didn’t do it? I had to change the link structure, then I just changed it back. Works now! Thanks again, Steve!
-
June 1, 2015 at 2:13 pm #3792
SteveKeymasterGlad it worked! That’s one of my favorite Piklist filters… so awesome.
Closing this ticket.
-
-
AuthorPosts
- The topic ‘No-title CPT permalink?’ is closed to new replies.