Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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...

share|improve this question

closed as too localized by toscho Jul 6 '12 at 20:19

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

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
 }
}
?>
share|improve this answer

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