Corregir caracteres raros por acentos en wordpress

wordpress y mysql wordpressLa semana pasada ayude a un amigo a reparar un error que tuvo al momento de actualizar su blog desde una versión algo viejita de wordpress a la 2.9.1, no se realmente que versión tenía pero no se completo el upgrade y su sitio quedo en blanco porque no se conectaba wordpress a la base de datos.

Me dio acceso a su servidor y resubí la versión mas nueva de wp manualmente por FTP. Después de moverle un poco al fin logre que se conectará y visualizará el blog, pero había un problema.. Los caracteres latinos con acentos, tildes y guiones (á,é, í, ó, ú, ñ, Ñ, etc) no se visualizaban y mostraban caracteres extraños en ves de ellos ( ÔÃ0Ôà Ãa à áéÃà ³Ãº), no se si la base de datos usaba otro codificación para guardar los datos diferente a utf8 y se quedo de esa forma, porque revisando la base de datos esos caracteres reemplazaron a las letras que debían aparecer y ya aparecían como un dato insertado, en fin.

Para solucionar esto hay varias formas, yo les dejaré 2. Lo que vamos hacer es reemplazar los caracteres raros por el valor real que les corresponde a cada conjunto de caracteres “raros”, por ejemplo Ô por á .

1.- Utilizando Notepad++.
Hacemos un respaldo de nuestra base de datos y la guardamos en formato “.sql” en algún lugar de nuestra computadora, abrimos el archivo con Notepad++ y presionamos las teclas “Control + H“, de esta forma se abrirá un cuadro de búsqueda y reemplazo.  Y reemplazamos colocando en la primer  casilla “Buscar” los caracteres raros que vamos a reemplazar y en la segunda la el caracter real que debe ser.

wordpress caracteres raros y extraños por acentosCaracteres que debemos reemplazar:

  • ñ por ñ
  • á por á
  • ó por ó
  • Ã por í
  • íº por ú
  • í‘ por Ñ
  • ú por ú
  • í© por é
  • – por –

Ventaja: El 100% de los caracteres raros son reemplazados rápidamente en solo 6 reemplazos.
Desventaja: El tener que descargar y volver a subir tu base de datos, sobre todo cuando son bases de datos muy pesadas. Otra es que si la base de datos es mucho mayor a la memoria RAM de tu computadora se tardará mucho o simplemente se trabará el programa al abrirla o al intentar hacer el reemplazo.

2.- Desde Phpmyadmin utilizando querys SQL (REPLACE).
Esta forma de hacerlo me la encontré en el blog de guatewireless y es la que utilice, se trata de hacer un Remplazo en los campos de una tabla utilizando la sentencia REPLACE de SQL de la siguiente forma.
Sintaxis:

UPDATE tabla SET campo = REPLACE(campo,’texto a buscar’,’nuevo texto’);

En guate compartieron las consultas para reemplazar caracteres en los títulos, contenido, comentarios, autores en los comentarios y para los que usan Yet another related, pero estas no solucionan todos los errores, cree todas las consultas que sirven para reemplazar lo mas importante para no perder el SEO del blog(sobre todo en un blog que google indexa muy rápido).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
Nombre que se muestra en el blog de cada autor.
UPDATE wp_users SET display_name = REPLACE(display_name, 'ñ', 'ñ');
UPDATE wp_users SET display_name = REPLACE(display_name, 'á', 'á');
UPDATE wp_users SET display_name = REPLACE(display_name, 'ó', 'ó');
UPDATE wp_users SET display_name = REPLACE(display_name, 'Ã', 'í');
UPDATE wp_users SET display_name = REPLACE(display_name, 'íº', 'ú');
UPDATE wp_users SET display_name = REPLACE(display_name, 'í‘', 'Ñ');
UPDATE wp_users SET display_name = REPLACE(display_name, 'ú', 'ú');
UPDATE wp_users SET display_name = REPLACE(display_name, 'í©', 'é');
UPDATE wp_users SET display_name = REPLACE(display_name, '–', '–');
 
Nombre del post
UPDATE wp_posts SET post_name = REPLACE(post_name, 'ñ', 'ñ');
UPDATE wp_posts SET post_name = REPLACE(post_name, 'á', 'á');
UPDATE wp_posts SET post_name = REPLACE(post_name, 'ó', 'ó');
UPDATE wp_posts SET post_name = REPLACE(post_name, 'Ã', 'í');
UPDATE wp_posts SET post_name = REPLACE(post_name, 'íº', 'ú');
UPDATE wp_posts SET post_name = REPLACE(post_name, 'í‘', 'Ñ');
UPDATE wp_posts SET post_name = REPLACE(post_name, 'ú', 'ú');
UPDATE wp_posts SET post_name = REPLACE(post_name, 'í©', 'é');
UPDATE wp_posts SET post_name = REPLACE(post_name, '–', '–');
 
Titulos en los post
UPDATE wp_posts SET post_title = REPLACE(post_title, 'ñ', 'ñ');
UPDATE wp_posts SET post_title = REPLACE(post_title, 'á', 'á');
UPDATE wp_posts SET post_title = REPLACE(post_title, 'ó', 'ó');
UPDATE wp_posts SET post_title = REPLACE(post_title, 'Ã', 'í');
UPDATE wp_posts SET post_title = REPLACE(post_title, 'íº', 'ú');
UPDATE wp_posts SET post_title = REPLACE(post_title, 'í‘', 'Ñ');
UPDATE wp_posts SET post_title = REPLACE(post_title, 'ú', 'ú');
UPDATE wp_posts SET post_title = REPLACE(post_title, 'í©', 'é');
UPDATE wp_posts SET post_title = REPLACE(post_title, '–', '–');
 
Contenido de los post
UPDATE wp_posts SET post_content = REPLACE(post_content, 'ñ', 'ñ');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'á', 'á');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'ó', 'ó');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'Ã', 'í');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'íº', 'ú');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'í©', 'é');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'ú', 'ú');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'í‘', 'Ñ');
 
Contenido reducido (cuando se usa excerpt)
UPDATE wp_posts SET post_excerpt = REPLACE(post_excerpt, 'ñ', 'ñ');
UPDATE wp_posts SET post_excerpt = REPLACE(post_excerpt, 'á', 'á');
UPDATE wp_posts SET post_excerpt = REPLACE(post_excerpt, 'ó', 'ó');
UPDATE wp_posts SET post_excerpt = REPLACE(post_excerpt, 'Ã', 'í');
UPDATE wp_posts SET post_excerpt = REPLACE(post_excerpt, 'íº', 'ú');
UPDATE wp_posts SET post_excerpt = REPLACE(post_excerpt, 'í‘', 'Ñ');
UPDATE wp_posts SET post_excerpt = REPLACE(post_excerpt, 'ú', 'ú');
UPDATE wp_posts SET post_excerpt = REPLACE(post_excerpt, 'í©', 'é');
UPDATE wp_posts SET post_excerpt = REPLACE(post_excerpt, '–', '–');
 
CategoríAS de los post
UPDATE wp_posts SET post_category = REPLACE(post_category, 'ñ', 'ñ');
UPDATE wp_posts SET post_category = REPLACE(post_category, 'á', 'á');
UPDATE wp_posts SET post_category = REPLACE(post_category, 'ó', 'ó');
UPDATE wp_posts SET post_category = REPLACE(post_category, 'Ã', 'í');
UPDATE wp_posts SET post_category = REPLACE(post_category, 'íº', 'ú');
UPDATE wp_posts SET post_category = REPLACE(post_category, 'í‘', 'Ñ');
UPDATE wp_posts SET post_category = REPLACE(post_category, 'ú', 'ú');
UPDATE wp_posts SET post_category = REPLACE(post_category, 'í©', 'é');
UPDATE wp_posts SET post_category = REPLACE(post_category, '–', '–');
 
Tags de los post
UPDATE wp_terms SET name = REPLACE(name, 'ñ', 'ñ');
UPDATE wp_terms SET name = REPLACE(name, 'á', 'á');
UPDATE wp_terms SET name = REPLACE(name, 'ó', 'ó');
UPDATE wp_terms SET name = REPLACE(name, 'Ã', 'í');
UPDATE wp_terms SET name = REPLACE(name, 'íº', 'ú');
UPDATE wp_terms SET name = REPLACE(name, 'í‘', 'Ñ');
UPDATE wp_terms SET name = REPLACE(name, 'ú', 'ú');
UPDATE wp_terms SET name = REPLACE(name, 'í©', 'é');
UPDATE wp_terms SET name = REPLACE(name, '–', '–');
 
Nombre meta de los post
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'ñ', 'ñ');
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'á', 'á');
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'ó', 'ó');
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'Ã', 'í');
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'íº', 'ú');
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'í‘', 'Ñ');
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'ú', 'ú');
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'í©', 'é');
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, '–', '–');
 
Comentarios 
UPDATE wp_comments SET comment_content = REPLACE(comment_content, '–', '–');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, 'ñ', 'ñ');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, 'á', 'á');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, 'ó', 'ó');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, 'Ã', 'í');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, 'íº', 'ú');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, 'í©', 'é');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, 'ú', 'ú');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, 'í‘', 'Ñ');
 
Autores en los comentarios
UPDATE wp_comments SET comment_author = REPLACE(comment_author, '–', '–');
UPDATE wp_comments SET comment_author = REPLACE(comment_author, 'ñ', 'ñ');
UPDATE wp_comments SET comment_author = REPLACE(comment_author, 'á', 'á');
UPDATE wp_comments SET comment_author = REPLACE(comment_author, 'ó', 'ó');
UPDATE wp_comments SET comment_author = REPLACE(comment_author, 'Ã', 'í');
UPDATE wp_comments SET comment_author = REPLACE(comment_author, 'íº', 'ú');
UPDATE wp_comments SET comment_author = REPLACE(comment_author, 'í©', 'é');
UPDATE wp_comments SET comment_author = REPLACE(comment_author, 'ú', 'ú');
UPDATE wp_comments SET comment_author = REPLACE(comment_author, 'í‘', 'Ñ');

Ventajas: Todo se hace desde el servidor y no hay necesidad de descargar la base de datos. Puede quedar al 100% al igual que la forma anterior pero es mas lento el proceso.
Desventajas: Se deben crear 6 consultas por cada campo de una tabla(una por una) y si se tienen instalados plugins que utilicen tablas propias son mas.

Y aquí se termina, espero les sea de utilidad.

    1. Martin 26 marzo 2010
    2. documentales 7 mayo 2010
      • danielmd 7 mayo 2010
    3. david 22 mayo 2010
    4. Gabo 13 junio 2010
      • danielmd 13 junio 2010

    Leave a Comment

    Este sitio usa Akismet para reducir el spam. Aprende cómo se procesan los datos de tus comentarios.