how to change question/post slug programatically?

Solved4.63K viewsUpdates
0

Hi,

I have the following code to use automatically to use postId as slug instead of post title.

add_action( 'save_post', 'using_id_as_slug', 10, 2 );
function using_id_as_slug($post_id, $post){
	global $post_type;
	if($post_type=='post'){
		if (wp_is_post_revision($post_id))
			return false;
		remove_action('save_post', 'using_id_as_slug' );
		wp_update_post(array('ID' => $post_id, 'post_name' => $post_id ));
		add_action('save_post', 'using_id_as_slug' );
	}
}

and it works for normal post. but doesn’t work for anspress questions.

I am suspecting $post_type==’post’ doesnt apply to anspress? Could you please provide me any insight as to how to make it work? thanks!

i tried changing it to $post_type==’question’, but no luck still.