Search and replace MySQL content

Today I switched from the Code Markup to the Code Snippet WordPress plugin. Therefore I had to change the way the code block is activated. This is a time consuming job if you have to do this by hand, so I figured out there should be a smarter way of doing this. Check out the MySQL replace function below:

update [table_name] set [field_name] = replace([field_name],'[string_to_find]','[string_to_replace]');

And so the above translated to the lines I needed:

mysql> update wp_vleeuwen_posts set post_content = replace(post_content, '<pre><code>', '');
Query OK, 35 rows affected (0.06 sec)
Rows matched: 72  Changed: 35  Warnings: 0

mysql> update wp_vleeuwen_posts set post_content = replace(post_content, '</code></pre>', '[/ code]');
Query OK, 35 rows affected (0.01 sec)
Rows matched: 72  Changed: 35  Warnings: 0


Notice the little typo I had to make in order to let the above code snippet work ([/ code]).

WP add media problem

When using WordPress version 2.5.1 (Debian Lenny package) it is not possible to add/upload media using the “Add media” button in the editor. If you click on Add an image, a new window appears where you should have the option buttons “Browse” and “Upload”, but they’re gone. What’s left is a “Choose files to upload” button that won’t do anything.

I have experienced this problem when using Mozilla Firefox 3.0.14 on Linux with the Shockwave Flash add-on enabled.

Workaround: When this add-on is disabled the add media problem will not occur. To disable the add-on, open Firefox and go to ‘Tools’ -> ‘Add-ons’ and select disable Shockwave Flash.

Limit WordPress archives

Since switched over to a new theme I needed to rearrange the way the sidebar should look. The list of archives was just to long, think 20 months is the default, to be aesthetic correct. So I started to look for a limit setting in de admin interface of WordPress, but could not find a way to change the limit. I probably looked over it. So browsing through the php scripts I found the file responsible for the way the archives section behaves.

I use WordPress version 2.5.1 from the Debian lenny repository

Edit the following file:

wordpress/wp-includes# vi general-template.php

And look for the following function:

# cat -n general-template.php
356	function wp_get_archives($args = '') {
357		global $wpdb, $wp_locale;
359		$defaults = array(
360			'type' =&gt; 'monthly', 'limit' =&gt; '<strong>10</strong>',
361			'format' =&gt; 'html', 'before' =&gt; '',
362			'after' =&gt; '', 'show_post_count' =&gt; false
363		);

Change the options you whish, I lowered the limit to 10 months.