Posts Tagged phpMyAdmin

How to fix mangled HTML in WordPress posts using SQL

There are quite a few ways that source code and other preformatted text can get mangled in WordPress, such as a rich-text editor, or even by the export/import process.

When I speak of ‘mangled’, I mean unnecessarily HTML-encoded. Left and right angle brackets (the < and > signs), quotation marks (the ” symbol), and ampersands (the & symbol) get HTML-encoded to &lt;, &rt;, &quot;, and &amp;. This can seriously mangle sourcecode, as well as making other text seriously ugly.

It can become a huge time waste to try to go back and edit all your affected posts one at a time to fix mangled code, even with search-and-replace.

Instead, there’s an easy and straight-forward way to do it in SQL, that you can execute from phpMyAdmin, MySQL Workbench, or whatever you fancy.

Simply run each of the following queries on your WordPress database, and feel free to edit them as you like.

update wp_posts set post_content = replace(post_content, '&quot;', '"');
update wp_posts set post_content = replace(post_content, '&gt;', '>');
update wp_posts set post_content = replace(post_content, '&lt;', '<');

Have any others to suggest? Please feel free to do so in the comments below. Thanks!

, , ,

Leave a comment

How to find a keyword in your WordPress posts using SQL

If you have a lot of WordPress posts and might want to find all posts containing a certain keyword for any reason, you can start by using the following SQL code, which was taken from this post. I used this in phpMyAdmin for a MySQL database. Make sure you are in the correct database first!

You can substitute any keyword for ‘needle’ below, but you must have the single-quotes and percent signs around it.

SELECT ID FROM wp_posts WHERE post_content LIKE '%needle%';

Example: Let’s say you use the NG Gallery plugin, which has you add a tag to all your posts to include said gallery. Now you find to find all posts which have that NG Gallery tag in them. The following query would work:

SELECT ID FROM wp_posts WHERE post_content LIKE '%nggallery%';

This can also be built upon for find-and-replace operations.

Keep in mind, you can really muck things up using SQL. Make a backup first if you don’t know what you’re doing!

Questions, comments, and feedback are always welcome. Thanks!

, , , , ,

Leave a comment

Forcing SSL for phpMyAdmin

After configuring WordPress to force SSL in the administration area, I was in phpMyAdmin and realized that it’s also not configured to do the same by default.

From the phpMyAdmin Wiki, add the following line at the end of your /etc/phpmyadmin/ file

$cfg['ForceSSL'] = TRUE;

This will cause sessions to force SSL.

If you’re having issues making this work for you, check out my article involving Apache and SSL.

Questions, comments, and feedback are welcome.

, , , ,

Leave a comment