I am using a function to insert some post data and i am having problems with the title/title - slug. The title is random selected from an array, some title have ?
, !
or .
(dots)
I notice wp_insert_post
doesn't clean up the title so in the title slug (permalink) i see the ?
, !
or dots. How can i fix this? Any WP built-in function?
This is my function
function my_add_post($title, $content){
// Create post object
$title = str_replace('.','',$title);
$title = str_replace('?','',$title);
$my_post = array(
'post_title' => $title,
'post_content' => $content,
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array(1)
);
// Insert the post into the database
wp_insert_post( $my_post );
}