Support » Fixing WordPress » Set post name to post id

  • I am trying to set a custom post types name to be the id of the post but i cant get it to work

    I tried this snippet

    add_filter('the_title', 'add_id_to_title', 10, 2);
    function add_id_to_title($title, $post_id) {
        //use the id to check the post type and only add the id if it has a type of "post"
        if(get_post_type($post_id) == "message")
            $title = $post_id;
        return $title;

    But it does not set the post name it looks like it does on the post type page but name is just (Auto Draft)
    i use pods to create the custom post type and have removed the title as it is not needed for my website.
    The id is for moderation only

    • This topic was modified 5 months, 3 weeks ago by mightyx3n.
Viewing 1 replies (of 1 total)
  • Moderator bcworkz


    Your code works for me on my site. The only change was the post type “message” was changed to one of my own.

    It’s unclear where “Auto Draft” (post status) is even coming from. It doesn’t exist in your code at all. Apparently some other code is changing the title after yours had already executed. Try changing the 10 priority in the add_filter() call to a much larger integer, like 9999. Then your callback should have the final say in the matter.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.