Was looking at the below post which does something similar to what I am trying to do...it clears out the post_name (slug) and recreates based on post_title. (for a specific post type)

Create slugs programmatically

FROM POST_CONTENT (what I'm trying to do)

I am trying to create post_name from post_content for a specific post type, in a similar fashion, however, cannot use the post title. The post content fields in this case actually contain the correct number of words for a post title, so as long as they are sanitized, they would make good slugs.

Hoping somebody can help with a code sample similar to the above...

link|improve this question
feedback

1 Answer

To complete the post you linked to:

Create a .php file in root of your WordPress directory and write:

<?php
require( 'wp-load.php' );

 $urunler = array(
'order'          => 'ASC',
'post_type'      => 'urun',
'post_status'    => null,
'numberposts'    => -1,
);

$tumurunler = get_posts($urunler);
if ($tumurunler) {
  foreach ($tumurunler as $urun) {
    $urun->post_name = sanitize_title($urun->post_content);
 // $urun->post_name = sanitize_title(substr($urun->post_content, 0, 50)); // to use this if you have long post contents
    wp_update_post( $urun );   // Update the post into the database
 }
}
?>
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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