Support » Plugins » [Plugin auto-create categories] get_the_title returning 'Auto Draft'

  • Hi all,

    I’m building a plugin to create a new category every time a new page is created, and naming each one ‘Sidebar: $page_title’. For this, I am hanging a function from save_post:

    In plugin .php:
    add_action('save_post', 'create_sidebar_cat');

    In functions.php

    function create_sidebar_cat($post_id)
             if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
             $pcheck = $_GET["post_type"];
             if($pcheck != "page") return;
             if ( !wp_is_post_revision( $post_id ) )
                $post_title = get_the_title( $post_id );
                $cname = 'Sidebar: '.$post_title;
                wp_create_category ($cname, 3);}

    It is working to a certain extent – the category is being created, and with the correct parent (id 3). But it is being named ‘Sidebar: Auto Draft’. Does anyone know why this is happening, or can suggest a better way of calling the new page title when ‘publish’ is clicked?

    Many thanks in advance,


Viewing 3 replies - 1 through 3 (of 3 total)
  • moving this to the sub-forum, as it seems more appropriate there

    [mod: redundant duplicate removed]

    im new here, but sounds like the post hasn’t been saved/published yet. Why not get the title from the $_GET array?



    Thanks for the suggestion netcs. I just gave that a go, but $_GET(["post_title"]; is empty. The autodraft message is gone as well now.

    The somewhat clumsy way I tested this was by adding this code to send an email to myself:

    $post_title = $_GET["post_title"];
    $cname = 'Sidebar: '.$post_title;
    $catmessage = "The GET title is ".$GET["post_title"]." and the variable is ".$post_title.". The cat name is ".$cname;
    mail("","New category created",$catmessage);

    Any other ideas?


Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin auto-create categories] get_the_title returning 'Auto Draft'’ is closed to new replies.