titles fixed

Next stage in the blog update was to fix the issue I’d had with blogger (or at least my own blog) which is that the posts didn’t have proper titles. I had always put the titles between <title> header tags in the post’s text field, but wanted to strip out the titles to the actual title field. Now that I’m using WordPress it’s much easier to do this kind of thing because I have access to the posts on my own database.

So step one was to get the headers out of the post fields, and insert them into the title field:

update wp_posts
set post_title = substring (post_content, locate ('<h4>', post_content) + 4, locate ('</h4>', post_content) - locate ('<h4>', post_content) -4) where post_title = '' and locate ('<h4>', post_content) > 0;

The where clause makes sure I’m only updating posts which don’t already have a title and that have the header tag in the post.

Now that the titles had been updated we still had a problem because the titles were still in the actual post text, so need to just strip those out:

update wp_posts
set post_content = right (post_content, char_length (post_content) - locate ('</h4>', post_content) - 4) where locate ('<h4>', post_content) > 0;

I’m sure there’s a more elegant way of doing this, but it worked, and for now I’m really enjoying having a bit more control over my own posts. Next step will be to categorize all the old uncategorized posts.

One Response to “titles fixed”

  1. Richard says:

    I guess the process is so much easier if you know something about software and can write your own SQL statements. Imagine if you didn’t know that, and had to copy over all the title posts manually.

Leave a Reply