WordPress.org

Support

Support » How-To and Troubleshooting » Updating post_name to include post ID almost got it but need help

Updating post_name to include post ID almost got it but need help

  • Pete
    Participant

    @angio

    I’m using a form to create posts. Before the redirect i’m updating the post_name and including the post ID at the end. The code below is almost working. It’s creating a post name like post_name-48 so I got the post ID there but why isn’t post_name displaying as the post name and only as a string. I pieced together the function below the best I could and help is appreciated. Thanks

    // Update post slug
    $my_post['ID'] = $pid;
    $my_post_name = 'post_name' . "-" . $pid;
    $my_post['post_name'] = $my_post_name;
    
    // Update the post into the database
      wp_update_post( $my_post );
Viewing 1 replies (of 1 total)
  • I think you need to use the .= operator to add your term to the post name:

    $my_post['post_name'] .= $my_post_name;

    Looks like you may also need a space in front of ‘post_name’: ‘ post_name’

Viewing 1 replies (of 1 total)
  • The topic ‘Updating post_name to include post ID almost got it but need help’ is closed to new replies.