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,
Iain