0

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 );   
}

1 Answer 1

1

Any WP built-in function?

Yes, sanitize_title.

2
  • tx, i am also trying wp_strip_all_tags
    – alex
    Commented Nov 15, 2013 at 8:39
  • 1
    @alex wp_strip_all_tags is useless. WordPress already strips all tags when you use sanitize_title.
    – gmazzap
    Commented Nov 15, 2013 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.