Viewing 7 reply threads
  • Author
    Posts
    • #3759
      gospelnerd
      Member

      How 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}’

    • #3760
      Steve
      Keymaster

      Piklist has a filter, piklist_empty_post_title, that may help you. Check out this support ticket >

      Let us know if that helps.

    • #3761
      gospelnerd
      Member

      Well, 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?

    • #3763
      Steve
      Keymaster

      This should work. Place it in your main plugin file or your themes functions.php file:

      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'];
      }
      
    • #3788
      gospelnerd
      Member

      That’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}’

    • #3789
      Steve
      Keymaster

      @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.

    • #3791
      gospelnerd
      Member

      Aww.. 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!

    • #3792
      Steve
      Keymaster

      Glad it worked! That’s one of my favorite Piklist filters… so awesome.

      Closing this ticket.

Viewing 7 reply threads
  • The topic ‘No-title CPT permalink?’ is closed to new replies.