Creating a custom slug

Hey so currently when I post to WordPress (Automatically) I am using something like this

$content = '<iframe width="100%" height="315" src="https://www.youtube.com/embed/'.$row['vid_code'].'?vq=hd1080&modestbranding=1&autoplay=1&controls=1&iv_load_policy=3&loop=1&rel=0&showinfo=0&color=white&autohide=0&disablekb=1" frameborder="0" allowfullscreen></iframe>';


// Create post object
$my_post = array(
     'post_title'    => wp_strip_all_tags( trim( $row['title'] ) ),
     'post_content'  => $content,
     'post_status'   => 'publish',
     'post_author'   => 1,
     'post_category' => array( 3 ),
     'post_date' => date('Y-m-d H:i:s')
);

Now i am wondering what would I need to add in order for me to get the '. $row['video'] .' portion of my code to be my websites custom slug.

Related posts

1 comment

  1. Good question.

    Try adding this into your code and it should return what you’re looking for.
    $new_url = sanitize_title(''.$row['vid_code'].'');.

    So it would look like this below.

    $content = '<iframe width="100%" height="315" src="https://www.youtube.com/embed/'.$row['vid_code'].'?vq=hd1080&modestbranding=1&autoplay=1&controls=1&iv_load_policy=3&loop=1&rel=0&showinfo=0&color=white&autohide=0&disablekb=1" frameborder="0" allowfullscreen></iframe>';
    
    
    // Create post object
    $my_post = array(
         'post_title'    => wp_strip_all_tags( trim( $row['title'] ) ),
         'post_content'  => $content,
         'post_status'   => 'publish',
         'post_author'   => 1,
         'post_category' => array( 3 ),
         'post_date' => date('Y-m-d H:i:s')
    );
    
    $new_url = sanitize_title(''.$row['vid_code'].'');
    

Comments are closed.